Git Branching
Learn How to Manage Multiple Versions of a Project with Branching
StartKey Concepts
Review core concepts you need to learn to master this subject
The Master Branch
Creating a New Branch
Viewing the Current Branch
Merge Conflicts
Deleting a Branch
Merging Branches
The Master Branch
The Master Branch
$ git init
Initialized empty Git repository in /home/ccuser/new-project/.git/
$ echo "Hello World!" >> hello.txt
$ git add hello.txt
$ git commit -m 'initial commit'
[master (root-commit) bb0e565] initial commit
1 file changed, 1 insertion(+)
create mode 100644 hello.txt
$ git branch
* master
In Git, the main project is completed on the master
branch. Making your first commit in a new git repository will automatically create a master
branch. Create new branches from the master
branch to develop new features for a project. These branches can be merged into master
at a later time to incorporate the new features. You can use git branch
to check what branch you’re on.
- 1Up 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…
- 2The 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…
- 3Right 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…
- 4Great! 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…
- 5Congratulations! 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…
- 7The 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…
- 8Let’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 …
- 9In 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…
- 10Let’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
Birthday Party
It's time to build fluency in Git merging. In this next Pro Project, we're going to practice merging to master in Git so you can hone your skills and feel confident taking them to the real world. Why? Learning how to merge your branch to master will allow you safely include your code with the main codebase. What's next? A birthday party, last minute planning, more Git. You got this!
Ruby Time Calculator
It's time to build fluency in Git merging. In this next Pro Project, we're going to practice merge conflicts in Git so you can hone your skills and feel confident taking them to the real world. Why? Merge conflicts are common when you work with many people on the same code. Practicing how to deal with them now will save you time later on. What's next? Conflicts, resolutions, more Git. You got this!
How you'll master it
Stress-test your knowledge with quizzes that help commit syntax to memory