DEV Community

Adam La Rosa
Adam La Rosa

Posted on

Git & Branches

I for one seem to always get carried away with my work. By noon a project will be working fine & come evening for some reason a change I've made will cause enough errors that I have to backtrack to find the bug. For far too long this entailed looking through directories of different saved files named with timestamps. Then my life turned around...

...then I discovered Git.

Git is a wonderful tool for working on a project and saving your progress at different times. Once it is installed on your system, just navigate into the project you'd like Git to work with and invoke a simple command.

git init

This will make the directory a working Git repository. What this means is that Git will keep track of changes you make to files, and when you're ready, take a "snapshot" of the differences. While Git has many MANY commands available to help in this task, my favorite is branches.

Git branches allow you to create a mirror of what you're working on. This way you can make any number of changes without worrying about breaking your project. It is if a parallel universe is created for your project for you to tinker in. Then, when you're satisfied with your changes you can "merge" them into your main branch.

All Git repositories start on a branch called "master". A new branch is created with the command:

git branch name-of-new-branch

By then typing "git branch" alone you can see a list of branches your repository has. To switch to the new branch one would type:

git checkout name-of-new-branch

Now you are actively working on the different branch. Make all the changes you like! None of these will affect the "master" branch. Once you are done with your modifications the changes can be "merged" into the master branch!

Top comments (0)