

The HEAD is detached and moves together with each new commit created. Is it possible to create a new commit while checkout to one? Time to find it out! git commit -m "commit message" We are currently checkedout to a remote branch. Checkout to a commit and see what happens with git checkout C0. Detached HEADĪs we have said before, HEAD always points to the currently checked out branch or commit. You can read more at Git Beginner's Guide for Dummies.Ĭreate your own Ruby on Rails project and try it out! Make Rspec tests on a different branch and commit the changes. bug fixing, new features etc), which is a good practice because it allows others to easily identify what changes to expect, and also for backtracking purposes to understand why a particular code change is implemented. It is a common practice to create a new branch for each task (e.g. Branching enables you to isolate your work from others.

Changes in the hello-world branch did not affect any other branch. Pointers always move to the latest commit in that branch that we checked out. The next step is to modify some files and create a new commit with git commit -m "commit message"Ī new commit C5 was created in the branch hello-world. Let's git checkout hello-world and see what happens.Īs you can see, the HEAD is now pointing to the hello-world branch instead of master.

HEAD always points to the currently checked out branch or commit. How does Git know which branch is currently checked out? This is where the HEAD pointer comes into play! You can see two different branches pointing to the same commit. Now, you are ready to use standard git add and git commit commands. To start working on it, you will need to switch to the branch with git checkout. Let's start with creating a new branch: git branch hello-world. Every next commit you make will go to the master branch until you decide to create and switch over to another branch. When you make your first commit in a repository, Git will automatically create a master branch by default. Whenever a new branch is created, Git creates a new pointer while keeping the original code base untouched. It works as a pointer to your next commits. What Is a Branch?īranch is an independent line of development.

This is where the branch function shines! Branch allows each developer to isolate his/her work from others by creating a new branch from the original code base. The problem raises, how to maintain different versions of the same code base? While some will be fixing bugs the others would be implementing new and different features. In the current era, most software development companies work in a collaborative environment where several developers contribute to the same source code.
