码迷,mamicode.com
首页 > 其他好文 > 详细

git 一般的使用操作

时间:2015-07-10 12:56:58      阅读:133      评论:0      收藏:0      [点我收藏+]

标签:

1.先在github上建立自己的repository,取名为yourRepo

2.创建本地库

ssh -T git@github.com # 在初始化版本库之前,先要确认认证的公钥是否正确
git init # 初始化版本库
git remote add origin git@github.com:yourname/yourRepo.git # 进入要上传的仓库,添加远程地址,注意:不要使用clone的地址

git add -A # 或者使用 git add * 添加所有仓库
git commit -m first commit # 提交并添加注释
git push origin master # 上传到github,如果git仓库中已经有一部分代码,会报(Non-fast-forward)错误

3.可能出现的问题及解决办法

如果git仓库中已经有一部分代码,是不允许直接覆盖代码上去,会出现(Non-fast-forward)错误,解决办法如下:

(1)强推,强制使用本地的代码覆盖git仓库中的内容git push -f
(2)先把git仓库中的内容fetch到本地然后merge后,再push,#git fetch #git merge,这2句命令等价于git pull

git pull 是可能会报错,解决办法如下:
(1)修改(.git/config)的内容如下
         [branch "master"]
         remote = origin
         merge = refs/heads/master

(2)如果不编辑config文件的话,可以使用如下命令行:

         git config branch.master.remote origin
         git config branch.master.merge refs/heads/master

然后再pull下再push就OK了

 

4.在第一次使用git push代码前需要先配置Git
(1)首先在本地创建ssh key;
$ ssh-keygen -t rsa -C "your_email@youremail.com"
后面的your_email@youremail.com改为你的邮箱,之后会要求确认路径和输入密码,我们这使用默认的一路回车就行。成功的话会在~/下生成.ssh文件夹,进去,打开id_rsa.pub,复制里面的key。回到github,进入Account Settings,左边选择SSH Keys,Add SSH Key,title随便填,粘贴key。

(2)为了验证是否成功,在git bash下输入:
$ ssh -T git@github.com
如果是第一次的会提示是否continue,输入yes就会看到:You’ve successfully authenticated, but GitHub does not provide shell access 。这就表示已成功连上github。
(3)把本地仓库传到github上去之前还需要设置username和email,因为github每次commit都会记录他们。
$ git config --global user.name "your name"
$ git config --global user.email "your_email@youremail.com"

git 一般的使用操作

标签:

原文地址:http://www.cnblogs.com/benlightning/p/4635152.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!