Git Beyond Basics: 7 Uncommon Git Commands Every Developer Should Know

📆 · ⏳ 3 min read · ·

Introduction

Git is a powerful tool for version control that allows developers to track changes to their code over time. However, the vast number of Git commands available can be overwhelming, and most developers only use a fraction of them.

In this article, we will explore seven uncommon Git commands that can help you to work more efficiently and effectively.

Commands

git stash

The git stash command allows you to temporarily save changes that are not yet ready to be committed.

This can be useful when you need to switch branches or pull in changes from another branch without committing your changes.

Example:

Terminal window
git stash
Saved working directory and index state WIP on feature-branch: 7f23a8a Add new feature

git bisect

The git bisect command helps you to find the commit that introduced a bug in your code.

You can use this command to quickly locate the commit that caused the bug and fix it.

Example:

Terminal window
git bisect start
git bisect bad
git bisect good v1.0

git rebase

Git rebase is a command that allows you to rewrite your Git history.

This can be useful if you need to clean up your commit history before merging a branch or if you need to apply a series of commits from one branch to another.

Example:

Terminal window
git checkout feature-branch
git rebase main

git revert

If you ever need to undo a commit, git revert is the command to use. Unlike git reset, git revert allows you to undo a commit without removing it from your Git history

This is useful if you need to undo a commit that has already been pushed to a remote repository.

Example:

Terminal window
git revert 7f23a8a

git cherry-pick

The git cherry-pick command allows you to apply a single commit from one branch to another.

This can be useful when you need to apply a specific fix or feature to another branch without merging the entire branch.

Example:

Terminal window
git cherry-pick 7f23a8a

git blame

The git blame command allows you to see who last modified a specific line of code and when.

This can be helpful in identifying the author of a particular bug or issue.

Example:

Terminal window
git blame index.html

git submodule

The git submodule command allows you to include one Git repository as a subdirectory of another Git repository.

This can be useful when you need to include a shared library or tool in your project.

Example:

Terminal window
git submodule add https://github.com/user/repo.git

Conclusion

In this article, we have explored seven uncommon Git commands that can help improve your workflow and productivity. These commands can help you to work more efficiently, troubleshoot issues, and collaborate more effectively with your team.

By incorporating these commands into your daily workflow, you can become a more proficient Git user and take your coding skills to the next level.

You may also like

  • # git# engineering

    Selecting the Right Git Merging Strategy: Merge Commit, Squash and Merge, or Rebase and Merge

    Uncover the intricacies of Git merging strategies – merge commit, squash and merge, and rebase and merge. Discover the pros and cons of each approach and learn how to navigate the decision-making process based on your project's dynamics and team preferences.

  • # git# engineering

    5 Basic Git Commands Every Developer Must Know

    Learn the top 5 basic git commands with examples that you must know as a developer in 2020.

  • # engineering

    Learning Through Building — Engineering Advices

    Over the years, I have learned a lot of things through building projects. In this post, I will be sharing some of the advices that I have learned through my journey.