开发者

How to work with other person on one branch in Git?

I'm working on some feature with my co-worker. We created topic-branch. And everything is ok when we only merge everything - our branch on server with local copies and master to keep our branch up to date. But开发者_如何学Go it is not ideal workflow.

Could anyone point me a better solution?


I guess you want to work with your co-worker without having to use the main repository as middle hand. I'd add the other persons repository as a remote and create a branch that is tracking his topic-branch. The other person can then do the same, but set your local topic-branch as his upstream branch.

Something like

  1. git remote add coworker file:////coworkersComputer/path/to/repo
  2. git fetch coworker
  3. git checkout --track coworker/topic-branch

Here you can pull changes from your coworker. If you want to rebase stuff you can always create local branches and rebase them onto topic-branch.

Your coworker must set up your computer in similar fashion:

  1. git remote add yourRepo file:////..
  2. git fetch yourRepo
  3. git branch --set-upstream topic-branch yourRepo/topic-branch

A nice thing with this is that you can work in complete isolation without causing any troubles to other coworkers. You have already setup each other as remotes so 1. is only needed one time. 2 and 3. is only needed when you want to setup a new topic to work on.


This is how I like to do it. Each of you should work on your own branch. When integrating, checkout the master branch and pull from each of your branches (where you will have added, committed and pulled the relevant changes you want to get to production).

A continuous integration server like Integrity (www.integrityapp.com) should help.


My guess is that you are doing a git pull from the server, when really what you want is git fetch. The problem is that git pull automatically merges your local branch with the remote branch that it is tracking, but git fetch does not.

The solution would be to only use git fetch, and then either git merge origin/master or git rebase origin/master (replace master with the actual branch name) afterward, depending on what you want the history to look like.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜