CodeVault - Failing code | Part 2
Logo picture

3 GIT productivity features explained

I know there are some people in the community that use GIT on a day-to-day basis but only commit/pull/push while omitting some of the more useful features of it. I present to you 3 useful features, all related to committing, that will help your productivity and ease of change.

  1. git stash

    This is the simplest way to put what you have been working on away for a second in favor of an urgent bug fix. All you have to do is:

    git stash ... do whatever it is needed to fix an urgent bug fix or whatever else git stash pop

    After you git stash all your uncommitted changes go away in a temporary place which you can re-apply using git stash pop.

  2. Using multiple local branches

    I know it has been said time and time again that anyone with a serious enough project should be using multiple branches for their project. That is not always true for all projects, but even so, if you only have one branch on the upstream it doesn't mean you can't use multiple branches on you own local repository. Here's how you do it:

    git branch new-branch-name git checkout new-branch-name ... commit whatever you want on this branch while keeping the main branch intact for more urgent modifications git checkout master (or your main branch) git merge new-branch-name

    And voila! You have another way to quickly switch to another task if needed. Isn't that great?

  3. Selective commits

    Instead of committing all changes you can selectively choose which files go where using the git add command to add them and git commit -m ... to commit whatever you have added.

    Really mate? This is the "productivity tip" you're teaching? I have been using that since I was 5! I know I know, but bare with me, I have made this mistake where I didn't know what the stage area was for and was always committing all my changes using git commit -am .... I never knew there was an alternative for one and a half years.

    With that said, here are the steps:

    git add file_you_want_to_commit git commit -m "Message properly explaining your changes" git add another_file_you_want_to_commit git commit -m "Another message properly explaining your changes"

That has been it for this tutorial. Hope you got something out of it. I have published a video explaining these features a bit more in-depth. You can check it out here:

What are some of the features you have wished you knew before starting out using VCS?

Published on: 2018/10/26

Get notified when a blog post is released

+ Free Clean Coding Guide