I currently have Git setup with a central bare repository which is accessed by two developers via remote repositories. I've hit on a problem when I've created a branch and then tried to push that branch from a remote repository to the central bare respository, similiar to that in this post.
I've read that tracking branches were the best way to do this, but the Version Control with Git book that I'm reading says t开发者_JS百科hat as tracking branches are designed to follow the changes from another repository that they shouldn't be used for merges and commits.
Based on my current set up, what's the best way to handle different branches?
I had been intending to have a branch for each version / release of the software but it seems that the easiest way would be to create a separate repositories for each version / release.
First of all: you won't need an own repo for each version of your software. If you release, create a tag and that's all you need. Referencing this tag, you can always go back to the released version.
If you have a central repo where each of your two developers shall be allowed to push to, then you'll have to make that repo a bare repo (like the accepted answer in your referenced question recommends).
Bare repositories have no checked out working copy, therefore you can always push to them (at least as long as you fetched the latest version before).
But your scenario sounds a little different: if you have, for example, two computers where each one carries a working copy and want to push/pull between these two boxes, the solution is to have a branch that is only used while pushing to master from the other computer.
Following workflow (assuming you want to push changes of branch myfeature
from notebook
to the remote desktop
that has currently the branch myfeature
checked out:
On desktop
:
git checkout -b temp
Then, on notebook
:
git push desktop myfeature:myfeature
Back on desktop
:
git checkout myfeature
git branch -D temp
That's it.
Another alternative (in the case of two developers (alice and bob) working on the same branch) would be that – if bob wants to get the latest version of myfeature
from alice – he pulls the changes from alice instead of letting her push her changes into his repo. Assuming alice's computer is configured as remote alice
in bob's repo and bob has currently checked out the myfeature
branch.
Either bob does
git pull alice
if alice/myfeature
is configured as tracking branch for his myfeature
branch (set it with git branch --set-upstream myfeature alice/myfeature
). Or
git fetch alice
git merge alice/myfeature
if alice's myfeature
branch is not configured as tracking branch.
精彩评论