Thursday, April 14, 2011

Git Push :- Only Current Branch

Recently, when sharing a bare repository on my machine with one of the members on my team, we ran into a funny scenario. But first, it is probably worth mentioning the following information:

  • We are currently using git to push to svn
  • We have a master branch that is tracking the svn/trunk

I created a new bare repository that will allow us work together on a specific task. When using Git, you only want to push into a bare repository (a repo without a working directory), instead of the real one. He was able to pull the code just fine, but when he tried to push the changes into the bare repository, not only did it try to push the branch that we were currently working on, but it also tried to push the master branch as well. That is because the bare repository that I created, had a master branch, and so did his local, and therefore it was matching on that branches name. (Note: I was also experiencing this same behavior).

After Googling for an answer to the behavior and hoping to get the desired behavior of only pushing the changes from the branch that I am currently on, I found git push current branch, on StackOverflow. If you are like me, and want the desired behavior of only pushing the current branch that you are on to the remote repository, and not all of the branches, just run the following command in your git repository:

git config push.default tracking

There are other options besides 'tracking' but this is giving me the desired behavior that I was looking for...

Enjoy...

1 comment:

Anonymous said...

Use "upstream" in place of "tracking". "tracking" is a deprecated synonym for "upstream" - http://www.spinics.net/lists/git/msg151127.html