Git Branching
Lesson 1 of 1
  1. 1
    Up to this point, you’ve worked in a single Git branch called master. Git allows us to create branches to experiment with versions of a project. Imagine you want to create version of a story with…
  2. 2
    The diagram to the right illustrates branching. The circles are commits, and together form the Git project’s commit history. New Branch is a different version of the Git project. It conta…
  3. 3
    Right now, the Git project has only one branch: master. To create a new branch, use: git branch new_branch Here new_branch would be the name of the new branch you create, like photos or blur…
  4. 4
    Great! You just created a new branch. The master and fencing branches are identical: they share the same exact commit history. You can switch to the new branch with git checkout branch_name He…
  5. 5
    Congratulations! You have switched to a new branch. All the commands you do on master, you can also do on this branch. For example, to add files to the staging area, use: git add filename And…
  6. 6
    What if you wanted include all the changes made to the fencing branch on the master branch? We can easily accomplish this by merging the branch into master with: git merge branch_name For ex…
  7. 7
    The merge was successful because master had not changed since we made a commit on fencing. Git knew to simply update master with changes on fencing. What would happen if you made a commit on mast…
  8. 8
    Let’s say you decide you’d like to merge the changes from fencing into master. Here’s where the trouble begins! You’ve made commits on separate branches that alter the same line in conflicting …
  9. 9
    In Git, branches are usually a means to an end. You create them to work on a new project feature, but the end goal is to merge that feature into the master branch. After the branch has been integra…
  10. 10
    Let’s take a moment to review the main concepts and commands from the lesson before moving on. Git branching* allows users to experiment with different versions of a project by checking out se…

What you'll create

Portfolio projects that showcase your new skills

Pro Logo

How you'll master it

Stress-test your knowledge with quizzes that help commit syntax to memory

Pro Logo