Thursday, June 28, 2012

GIT Reference

I am getting absolutely tired of trying to find my GIT references again after I have found them and used them and for some reason I am unable to remember certain commands with git. I am going to use this post as a central location for all of the GIT references that I find with a short description of the command/section that I found useful there.

When creating a branch here are the steps that you want to follow:
1) First we need to create the remote branch so we have a place for us to start. We can do that with the following command:
git push origin [current-branch]:refs/heads/[branch-name]
So for example let's say that I wanted to create a new branch called bill-fix but I don't want to start at the master branch, I want to start at say our new-ui branch. So then my command would look like this:
git push origin new-ui:refs/heads/bill-fix
You can see the logic of the push command, in this example.

2) Next, we need to checkout this newly created branch so we can start work on it. This is the command for that:
git checkout --track -b [branch-name] origin/[branch-name]
So, this command is also pretty self explanatory. The first [branch-name] that appears is the name that you want your local branch to be, and the second has to be the same as the remote branch created. So using the example above, my new branch was named bill-fix but lets say that I want my local branch to be bill-fixed-everything but I want it to track the remote branch of bill-fix, then my command would look like this:
git checkout --track -b bill-fix-everything origin/bill-fix



The above steps will create a remote branch and then a local branch that you can edit that will track the newly created remote branch. There is also a way that you can create a local branch that is not remote so that way only you can see that branch. For more information about that please go to this site: http://git-scm.com/book/en/Git-Branching-Basic-Branching-and-Merging
This site also provides a good explanation about how git branches work so if you are confused about that please read it there.

No comments:

Post a Comment