DEV Community

Cover image for mastering git: the only essential commands you need to know to be a productive developer [pt 2] 🔥
 Khem Sok
Khem Sok

Posted on

mastering git: the only essential commands you need to know to be a productive developer [pt 2] 🔥

Image description

intro

this article is pt 2 of the mastering git series. see part 1 here. in this article, we will expand on those commands and introduce 7 additional git commands that are useful to your workflow.

8 - git status

this command displays the status of your local repository, including the changes that have been staged, changes that have been made but not stage, and untracked file.

$ git status
Enter fullscreen mode Exit fullscreen mode

9 - git diff

this command displays the difference between two snapshots of your repository. you can use it to see the changes you've made in your local repository compared to the remote repository, changes between different branches, or changes between different commits.

$ git diff HEAD # to compare the current branch with the latest commit

$ git diff branch1 branch2 # to compare two branches
Enter fullscreen mode Exit fullscreen mode

10 - git fetch

this command is used to retrieve changes from a remote repository, but it does not integrate them into your local repository. you can use it to see what changes have been made to a remote repository without affecting your local copy of the project.

$ git fetch origin # to fetch changes from the "origin" remote repository
Enter fullscreen mode Exit fullscreen mode

11 - git stash

this command is used to save changes that haven't been committed or staged to a temporary location. this can be useful if you need to switch to a different branch without having to commit.

$ git stash # to stash changes

$ git stash save "comment" # to save stash in the repository

$ git stash list # to list all stashes

$ git stash pop # to reapply previously stashed changes
Enter fullscreen mode Exit fullscreen mode

12 - git merge

this command allows you to combine changes from different branches into a single branch.

$ git merge branch-name # to merge changes from a branch named "branch-name" into the current branch

$ git merge branch-name --squash # to merge changes from a branch named "branch-name" into the current branch without bringing in the commit
Enter fullscreen mode Exit fullscreen mode

13 - git log

this command displays a log of all of the commits in your git repository. you can use it to see the history of your project and find specific commits

$ git log # to display the log of all commits

$ git log -5 # to display last 5 commits
Enter fullscreen mode Exit fullscreen mode

14 - git rebase

this command allows you to reapply a series of commits from one branch onto another branch. this is useful for reorganizing the history of a branch to make it more readable.

$ git rebase origin main # to reapply the commits from the branch origin main onto the current branch

Enter fullscreen mode Exit fullscreen mode

conclusion

here are additional seven git commands that is essential to your git workflow. hope you guys find this useful. thx.

Top comments (0)