Digitaleclub
Best for you!

5 advanced Git commands to up your Git game

If you’re a developer today, odds are you’ve learned Git, the version control system at the heart of modern software workflows. You know the basics — how repositories work, how to create branches and commit changes, and how to merge those changes and pull requests.

But now that you know the basics, it’s time to level up a little — to take advantage of some of the more powerful features of Git in your workflow. Here are five advanced Git features to make part of your current and future dev efforts.

Simplify commit histories with git rebase

When you have two branches in a project (e.g. a development branch and a master branch), both of which have changes that need to be combined, the git merge command is the natural and straightforward way to unify them. A merge adds the development history of one branch as a merge commit to the other. While this preserves both histories in complete detail, it can make the overall history of the project difficult to follow. In some cases, you might want a simpler and cleaner result. 

The git rebase command also merges two branches, but does it a little differently. A git rebase rewrites the commit history of one branch so that the other branch is incorporated into it from the point where it was created. This makes for a less noisy, and more linear, commit history for that branch. But it also means that potentially useful details about the other branch and the merge process are removed. 

To that end, rebase is best used when you have multiple private branches that you want to consolidate into a single, clean commit history before merging it with a public branch. This way, you’re getting the full benefit of rebase — making a commit history more linear and less noisy — without obscuring crucial details about the history of commits to your project.

Clean up merges with git merge --squash

Another way to make merges, and subsequent commits, less noisy is by using the --squash option in git merge. --squash takes all the commits from an incoming branch and flattens them into a single, consolidated commit.

Copyright © 2020 IDG Communications, Inc.

Leave A Reply

Your email address will not be published.