1

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 that 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.

Community
  • 1
  • 1
GrandMasterFlush
  • 6,269
  • 19
  • 81
  • 104
  • 1
    Have a look at git-flow. [This article](http://nvie.com/posts/a-successful-git-branching-model/) describes a sensible approach to using branches and tags to organise releases, versions etc; and [this one](http://jeffkreeftmeijer.com/2010/why-arent-you-using-git-flow/) gives an overview of the git-flow tools themselves. – Simon Whitaker Jun 08 '11 at 11:53
  • Thanks Simon, that looks quite promising. I'll take a good look at that. – GrandMasterFlush Jun 08 '11 at 12:40

1 Answers1

1

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.

eckes
  • 64,417
  • 29
  • 168
  • 201
  • Thanks @eckes, we are currently working with the bare repo model that you suggested and it was working fine until I tried checking back in the changes I made to a new branch. I'll give your comments a go. – GrandMasterFlush Jun 08 '11 at 12:58
  • @GrandMasterFlush: what **exactly** is the problem? Do you get any errors or what? – eckes Jun 08 '11 at 17:50