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

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


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值