您的位置:首页 > 其它

git实验之创建仓库

2012-06-22 19:05 183 查看

仓库创建

1. 本地新建一个git仓库

git --bare init

如果是需要作为服务器仓库的,推荐加—bare,否则以后其他仓库push代码到此仓库时会有一些麻烦。

具体可以参考:http://hi.baidu.com/mengdaant/item/62dc182908bf25f950fd87ff

添加文件

git add . // add all

git add \\*.txt // add all txt file

添加文件后,直接git commit就完成了仓库创建。

2. 本地克隆一个远程仓库

2.1 克隆远程仓库

git clone <name> <url> <directory>

这里,name可以不写,默认origin

directory也可以不写,默认使用远程git一样的根目录名。

2.2 添加远程仓库

git remoteadd <name> <url>

name可以任意取。 url必须是确实存在的git仓库。

3. 同步远程仓库代码到本地

git pull <name>

如果pull时提示“You asked me to pull without telling me whichbranch you want to merge with”,

说明本地有新建分支且已同步到服务器上,当从服务器下载代码时需要在本地config中配置该分支的merge信息。

配置时可以参考下面的例子:

$ git config branch.master.remote origin //master是分支名,origin是远程仓库名

$ git config branch.master.merge refs/heads/master

具体可参考http://hubingforever.blog.163.com/blog/static/171040579201232184549211/

4. 同步本地代码到远程仓库

git push <remote name> <branchname>

如果push时提示“ refusing to update checked out branch:refs/heads/master”,说明远程仓库创建是没有使用—bare选项。

解决这个冲突需要远程仓库管理员:

具体可以是将远程仓库当前分支切换到其他分支(如谁也不会使用的分支),

或者按照提示内容,设置denyCurrentBranch = ignore。

具体可参考http://hi.baidu.com/mengdaant/item/62dc182908bf25f950fd87ff
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: