Search code examples
gitversion-controlbranchgit-branchmsysgit

Basic Git branching


I am fairly new with Git and using Git on my windows machine through the command prompt. Currently I only have got one master branch and I want to create a new branch (current). I'm a bit confused with some of the commands.

Can someone give me some instructions to follow? I don't find git references very useful. I am not new to source control, just new to Git. Thanks.


Solution

  • Please read the Pro Git book.

    To make a branch in the same place as you are in history:

    git branch branch_name
    

    to switch to that branch use

    git checkout branch_name
    

    you can do both of those at the same time with:

    git checkout -b branch_name
    

    to keep alternating between the last 2 branches use

    git checkout -
    

    (this is the similar to the behaviour of cd -)

    Once you get better with the syntax of git, use a good branching strategy and stick with it. I use Branch per Feature.