Skip to main content

Command Palette

Search for a command to run...

Advanced Git and GitHub

Published
•3 min read•View as Markdown
Advanced Git and GitHub

Git Branching

Use a branch to isolate development work without affecting other branches in the repository. Each repository has one default branch and can have multiple other branches. You can merge a branch into another branch using a pull request.

Branches allow you to develop features, fix bugs, or safely experiment with new ideas in a contained area of your repository.

Git Revert and Reset

Two commonly used tools that git users will encounter are git reset and git revert. The benefit of both of these commands is that you can use them to remove or edit changes you’ve made in the code in previous commits.

Git Rebase and Merge

What Is Git Rebase?

Git rebase is a command that lets users integrate changes from one branch to another, and the logs are modified once the action is complete. Git rebase was developed to overcome merging’s shortcomings, specifically regarding logs.

What Is Git Merge?

Git merge is a command that allows developers to merge Git branches while the logs of commits on branches remain intact.

The merge wording can be confusing because we have two methods of merging branches and one of those ways is actually called “merge,” even though both procedures do essentially the same thing.

What’s the Difference Between Merge and Rebase?

A head-to-head comparison chart is the best way to illustrate the differences between Git merge and Git rebase.

Merge

Rebase

Merge lets you merge different Git branches.

Rebase allows you to integrate the changes from one branch into another.

Merge logs show you the complete history of commit merging.

Rebase logs are linear. As the commits are rebased, the history is altered to reflect this.

All the commits on a feature branch are combined into a single commit on the master branch.

All commits are rebased, and the same number of commits are added to the master branch.

Merge is best used when the target branch is supposed to be shared.

Rebase is best used when the target branch is private.

Merge preserves history.

Rebase rewrites history.


The Advantages and Disadvantages of Git Rebase and Git Merge

Git Merge Benefits

  • Merge is simple, straightforward, and familiar

  • Merge preserves the entire history in chronological order

  • Merge maintains the branch’s context

  • Merge creates a complete log that helps developers understand the big picture, showing when and how each merge occurred

  • Merge makes it easy for users to find mistakes and correct them

Git Merge Drawbacks

  • Merge isn’t very user-friendly

  • Merge’s exhaustive nature results in a clumsy history and log

  • Merge’s git log must be constantly and properly maintained, or devolve into a mess

Git Rebase Benefits

  • Rebase streamlines a possibly complex history

  • Rebase cleans up intermediate commits by turning them into a single commit, making life easier for DevOps teams

  • Rebase avoids the merge commit noise typically found in busy repos and busy branches

  • Rebase creates a streamlined, linear log

  • Rebase provides a lack of clutter, which facilitates project movement

Git Rebase Drawbacks

  • Users can’t track how and when commits were merged on the target branch

  • Rebase won’t work with pull requests since you can’t see minor changes someone else made

  • Rebase makes you resolve conflicts in the order they were created to continue the rebase. Unfortunately, this means more work for you, as you may need to fix the same conflicts repeatedly

  • Rebase lowers the feature down to a small number of commits, making it challenging to see the context