您的位置:首页 > 其它

Git 远程仓库管理,多人操作

2014-02-26 18:02 246 查看
Git 远程仓库管理,多人操作

本地

User A:

开始工作:
zdd@world:~$ mkdir testgit
zdd@world:~$ cd testgit/
zdd@world:~/testgit$ touch a b
zdd@world:~/testgit$ git init
Initialized empty Git repository in /home/zdd/testgit/.git/
zdd@world:~/testgit$ git add a b
zdd@world:~/testgit$ git commit
zdd@world:~/testgit$ git log
commit 55de5816875fdc54ae22cf46796f49407ff17011
Author: zdd <zddhub@gmail.com>
Date: Fri Dec 6 14:09:22 2013 +0800

User A -- First Commit
一段时间后,发现这不是一个人的活,于是请来了User B帮忙。

之前,先创建远程Git仓库,将本地版本push的服务器。
ssh git@gitservice "git init --bare ~/testgit.git"
Initialized empty Git repository in /mnt/sdc1/git/testgit.git/
提交到远程分支origin
git remote add origin git@gitservice:~/testgit.git
git push origin master
zdd@world:~/testgit$ git branch -a
* master
remotes/origin/master
告诉User B: git@gitservice:~/testgit.git

User B:
git clone git@gitservice:~/testgit.git
git pull
…
git push
User B提交了数据之后

User A:

zdd@world:~/testgit$ git pull
You asked me to pull without telling me which branch you
want to merge with, and 'branch.master.merge' in
your configuration file does not tell me, either. Please
specify which branch you want to use on the command line and
try again (e.g. 'git pull <repository> <refspec>').
See git-pull(1) for details.

If you often merge with the same branch, you may want to
use something like the following in your configuration file:
[branch "master"]
remote = <nickname>
merge = <remote-ref>

[remote "<nickname>"]
url = <url>
fetch = <refspec>

See git-config(1) for details.


此时User A需要设置当前branch的remote和merge,来制定需要合并的远程branch:
git config branch.master.remote origin
git config branch.master.merge refs/heads/master
此处也可以设置不同的branch,

然后push/pull顺利

OK

zdd@world:~/testgit$ git pull
remote: Counting objects: 5, done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
From gitservice:~/testgit
691854e..0c8b51b master -> origin/master
Updating 691854e..0c8b51b
Fast-forward
a | 1 +
1 file changed, 1 insertion(+)
zdd@world:~/testgit$ git log
commit 0c8b51b1021a7752441839a3c8e0ab3a3d1d067c
Author: zdd <zddhub@gmail.com>
Date: Fri Dec 6 15:08:25 2013 +0800

User B -- First Commit

commit 691854ee1e6b9fdf4dce52354a8b4386fe86b6ca
Author: zdd <zddhub@gmail.com>
Date: Fri Dec 6 14:48:46 2013 +0800

User A -- First Commit


关于push/pull 到底提交到那个分支,可通过git config 命令
git config branch.master.remote origin
git config branch.master.merge refs/heads/newbranch
或者

编辑config文件来设置
zdd@world:~/testgit$ vim .git/config

[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
[remote "origin"]
url = git@gitservice:~/testgit.git
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
remote = origin
merge = refs/heads/master
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: