一 配置github
1.注册github账户renle177
2.新建代码库linux-test
以上操作省略...
二 本地操作配置 (linux环境)
1.安装git及配置环境
yum -y install git
git config --global user.name "renle177"
git config --global user.email "380744432@qq.com"
ssh-keygen -t rsa -C "380744432@qq.com"
2.打开www.github.com->Accountsettings->SSH Keys->Add SSH Key->cp id_rsa.pub内容到此
3.创建本地仓库,并push到远程github
mkdir github;cd github
git init #初始化
touchREADME
git addREADME #提交到git本地仓库
git commit -m 'first commit' #提交文件,并注释信息
git remote add origin git@github.com:renle177/linux-test #连接远程github
git push -u origin master #更新本地文件到github
git status #查看文件状态
git remote -v #查看连接的哪个地址
git clone git@github.com:renle177/linux-test #克隆远程仓库到本地
假如本地已经存在了这个项目,而仓库中又有一新的更新,如何把更的合并到本地的项目中?
git fetchorigin #取得远程更新,这里可以看做是准备要取了
git merge origin/master #把更新的内容合并到本地分支/master
FAQ:
1.在执行
$ git remote addorigin git@github.com:defnngj/hello-world.git
错误提示:fatal: remote origin already exists.
解决办法:
$ git remote rm origin #就不会报错误了
2. 在执行
$ git push origin master
错误提示:error:failed to push som refs to.......
解决办法:
$ git pull origin master #先把远程服务器github上面的文件拉先来,再push 上去。