Why You Should Love Git As Much As I Do

Git is truly black magic, and that makes me feel like a dirty, dirty wizard. It’s amazing how much it offers, especially its Feature Branch Workflow. By changing branches and creating/editing files, your computer will instantly update to stay consistent with the project folder. So let’s begin by adding a basic index.html file. After adding the file, we must commit and stage it on the master branch.

git add index.html
git commit -m "Added index.html"

Now we have an initial file on the master branch. So let’s create a second branch called Dev. This branch will still have the index.html file simply because it’s branching from master.

git checkout -b Dev

Now we have two branches, master and Dev. In order to see these branches, type the command:

git branch

Now what I absolutely love about Git is its real-time project update. So let’s add a new file named test.html into the project folder. Now this file will appear in every branch because it’s unstaged.

Now we must commit and stage the file on the Dev branch like the index.html file:

git add test.html
git commit -m "Added test.html"

Here’s where the magic happens. Because the file was staged on Dev, it will only appear on the Dev branch, thanks to Git’s black magic. You can change back to the master branch with:

git checkout master

And pow! The file has magically disappeared! [Insert ghost emoji here] Spooky, right? So how do we get that file to appear on the master branch as well? It’s simple! Just merge the Dev branch.

git merge Dev

Git will then take the entire Dev branch, look at all staged files, and then merge it into your current branch. Now if you look again, you should now have the test.html file.

And just like that, you’ve watched some black magic before your eyes, as well as practice the basics of Feature Branch Workflow! Congrats! It’s really simple stuff yet has so much power, and I personally love it! I hope you find Git more interesting and start to work with it more!