git杂记

来源:互联网 发布:python 爬虫 百科 编辑:程序博客网 时间:2024/05/21 22:00

echo "# fluke" >> README.md

git initgit add README.mdgit commit -m "first commit"git remote add origin git@github.com:username/xxx.gitgit push -u origin master

设置Git的user name和email:

git config --global user.name "xxx"
git config --global user.email "xxx@xxxx.com"
//----------------------------------------------------------------------------------------------------------------------------------------------------------

1.获取源码:

git clone git@github.com:billyanyteen/github-services.git

2.这样你的机器上就有一个repo了。
3.git于svn所不同的是git是分布式的,没有服务器概念。所有的人的机器上都有一个repo,每次提交都是给自己机器的repo
仓库初始化:

git init

生成快照并存入项目索引:

git add

文件,还有git rm,git mv等等…
项目索引提交:

git commit

4.协作编程:
将本地repo于远程的origin的repo合并,
推送本地更新到远程:

git push origin master

更新远程更新到本地:

git pull origin master

补充:
添加远端repo:

git remote add upstream git://github.com/pjhyett/github-services.git

重命名远端repo:

git://github.com/pjhyett/github-services.git为“upstream”
</pre><pre code_snippet_id="414065" snippet_file_name="blog_20140702_10_2996331" class=" bash" name="code" style="white-space: pre-wrap; word-wrap: break-word; color: rgb(34, 34, 34); font-size: 0.875em; line-height: 1.62; margin-top: 0.625em; margin-bottom: 0.625em; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; background-color: transparent;"><span style="color: rgb(73, 73, 73); font-family: 'Microsoft YaHei', 'Helvetica Neue', SimSun; font-size: 14px; line-height: 21px; background-color: rgb(193, 207, 208);">生成一个新的SSH。</span><br style="color: rgb(73, 73, 73); font-family: 'Microsoft YaHei', 'Helvetica Neue', SimSun; font-size: 14px; line-height: 21px; background-color: rgb(193, 207, 208);" /><span style="color: rgb(73, 73, 73); font-family: 'Microsoft YaHei', 'Helvetica Neue', SimSun; font-size: 14px; line-height: 21px; background-color: rgb(193, 207, 208);">ssh-keygen -t rsa -C "email"</span><br style="color: rgb(73, 73, 73); font-family: 'Microsoft YaHei', 'Helvetica Neue', SimSun; font-size: 14px; line-height: 21px; background-color: rgb(193, 207, 208);" /><span style="color: rgb(73, 73, 73); font-family: 'Microsoft YaHei', 'Helvetica Neue', SimSun; font-size: 14px; line-height: 21px; background-color: rgb(193, 207, 208);">之后直接回车,不用填写东西。之后会让你输入密码。然后就生成一个目录.ssh ,里面有两个文件:id_rsa , id_rsa.pub</span><br style="color: rgb(73, 73, 73); font-family: 'Microsoft YaHei', 'Helvetica Neue', SimSun; font-size: 14px; line-height: 21px; background-color: rgb(193, 207, 208);" /><span style="color: rgb(73, 73, 73); font-family: 'Microsoft YaHei', 'Helvetica Neue', SimSun; font-size: 14px; line-height: 21px; background-color: rgb(193, 207, 208);">把这个SSH放到github上。</span><span style="color: rgb(73, 73, 73); font-family: 'Microsoft YaHei', 'Helvetica Neue', SimSun; font-size: 14px; line-height: 21px; background-color: rgb(193, 207, 208);">用公钥。先在GitHub上注册一个用户,然后进入account-setting ,把id_rsa.pub的内容复制进去就可以了。</span>
</pre><pre code_snippet_id="414065" snippet_file_name="blog_20140702_10_2996331" class=" bash" name="code" style="white-space: pre-wrap; word-wrap: break-word; color: rgb(34, 34, 34); font-size: 0.875em; line-height: 1.62; margin-top: 0.625em; margin-bottom: 0.625em; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; background-color: transparent;">
</pre><pre code_snippet_id="414065" snippet_file_name="blog_20140702_10_2996331" class=" bash" name="code" style="white-space: pre-wrap; word-wrap: break-word; font-size: 0.875em; line-height: 1.62; margin-top: 0.625em; margin-bottom: 0.625em; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; background-color: transparent;"><p style="color: rgb(51, 51, 51); margin-top: 0px; margin-bottom: 0.75em; font-size: 16px; line-height: 27.2000007629395px; text-indent: 1em; font-family: 'Helvetica Neue', Helvetica, Tahoma, Arial, STXihei, 'Microsoft YaHei', 微软雅黑, sans-serif; background-color: rgb(254, 254, 254);">如果使用git远程推送时出现如下问题:</p><pre class="prettyprint perl" style="color: rgb(51, 51, 51); padding: 0.3em; font-family: Monaco, Menlo, Consolas, 'Courier New', monospace; border-radius: 4px; margin-top: 0px; margin-bottom: 1.5em; line-height: 1.5em; word-break: break-all; word-wrap: break-word; white-space: pre-wrap; border: 1px solid rgba(0, 0, 0, 0.14902); border-image-source: initial; border-image-slice: initial; border-image-width: initial; border-image-outset: initial; border-image-repeat: initial; overflow-y: auto; background-color: rgb(246, 246, 246);">git <span class="keyword" style="font-weight: bold;">push</span> -u origin master    ssh: <span class="keyword" style="font-weight: bold;">connect</span> to host github.com port <span class="number" style="color: rgb(0, 153, 153);">22</span>: Connection refusedfatal: Could <span class="keyword" style="font-weight: bold;">not</span> <span class="keyword" style="font-weight: bold;">read</span> from remote repository.Please make sure you have the correct access rights<span class="keyword" style="font-weight: bold;">and</span> the repository <span class="keyword" style="font-weight: bold;">exists</span>.

可以采用如下方法:

vim .ssh/configHost github.comUser email@xxx.comHostname ssh.github.comPreferredAuthentications publickeyIdentityFile ~/.ssh/id_rsaPort 443

测试连接是否成功:

ssh -T git@github.comHi xxx! You've successfully authenticated, but GitHub does not provide shell access.

</pre><pre code_snippet_id="414065" snippet_file_name="blog_20140702_10_2996331" class=" bash" name="code" style="white-space: pre-wrap; word-wrap: break-word; color: rgb(34, 34, 34); font-size: 0.875em; line-height: 1.62; margin-top: 0.625em; margin-bottom: 0.625em; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; background-color: transparent;"><pre class="copyable-terminal-content js-zeroclipboard-target" style="box-sizing: border-box; overflow: auto; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 14px; margin-top: 0px; margin-bottom: 0px; font-stretch: normal; color: rgb(51, 51, 51);">

                                             
0 0