DEV Community

Abdelrahman Mohamed Allam
Abdelrahman Mohamed Allam

Posted on • Updated on

10 Advanced Git Commands Every Developer Should Know 🚀

post image

Git is a powerful version control system that every developer should know and use. In addition to the essential Git commands, there are also advanced commands that can help developers work more efficiently and effectively. In this blog post, we will discuss the next 10 advanced Git commands that every developer should know.

🔍 git log:

The git log command displays the commit history of a Git repository. By default, it shows the most recent commits first, along with information such as the commit hash, author, date, and commit message.

Here's an example of how to use git log:

1. Open a terminal or command prompt and navigate to your Git repository.

2. Run git log to display the commit history.

git log is a powerful command that can help you understand the history of changes in your Git repository. You can use it to track down bugs, find the origin of a specific feature or issue, or simply get a better understanding of how your codebase has evolved over time.

📦 git stash:

The git stash command comes in handy when you're working on a feature or bug fix and need to switch to a different task or branch. It allows you to temporarily save changes you've made to your working directory without committing them.

Here's how you can use git stash:

1. Make changes to your working directory using your favorite text editoror IDE.

2. Run git stash to save your changes in a new stash and remove them from your working directory.

3. Switch to the main branch to fix the critical bug.

4. After fixing the bug, switch back to the feature branch and run git stash apply to reapply the changes you saved earlier.

Overall, git stash is a useful command for temporarily saving changes and avoiding the need to create a new commit for unfinished work. It can help you keep your commit history clean and organized while allowing you to switch between tasks and branches with ease.

🍒 git cherry-pick:

The git cherry-pick command is used to apply changes from one commit to another branch. This command can be useful when you need to apply a specific change to a different branch. To cherry-pick a commit, run the following command:


git cherry-pick <commit hash>

Enter fullscreen mode Exit fullscreen mode

🔀 git rebase:

The git rebase command is used to rewrite the history of the repository by applying changes from one branch to another. This command can be used to combine multiple commits into a single commit or to remove unnecessary commits from the history. To rebase a branch, run the following command:


git rebase <base branch> <feature branch>

Enter fullscreen mode Exit fullscreen mode

🔍 git fetch:

The git fetch command is used to fetch changes from a remote repository without merging them into the local repository. Thiscommand can be useful when you want to see the changes made by others before merging them into your local repository. To fetch changes, run the following command:


git fetch

Enter fullscreen mode Exit fullscreen mode

🏷️ git tag:

The git tag command is used to create a tag for a specific commit. This command can be useful when you want to mark a specific commit as a release or a milestone. To create a tag, run the following command:


git tag <tag name> <commit hash>

Enter fullscreen mode Exit fullscreen mode

🔍 git blame:

The git blame command is used to display the author and commit information for each line of a file. This command can be useful when you want to see who made changes to a specific line of code. To display the author and commit information, run the following command:


git blame <file name>

Enter fullscreen mode Exit fullscreen mode

🔍 git bisect:

The git bisect command is used to find the commit that introduced a specific bug or issue. This command can be useful when you need to identify the commit that caused a regression. To use git bisect, run the following command:


git bisect start

git bisect bad <current commit>

git bisect good <last known good commit>

Enter fullscreen mode Exit fullscreen mode

🎉 Conclusion:

These are the next 10 advanced Git commands that every developer should know and use. By mastering these commands, developers can work more efficiently and effectively, andensure that their codebase is well-managed and maintained. From undoing changes and temporarily saving changes to rewriting the history of the repository and finding the commit that introduced a specific bug, these commands can help developers tackle complex code management tasks. So, start integrating these advanced Git commands into your workflow and take your coding skills to the next level! 🚀

Top comments (0)