Search This Blog

Git Commands that every developer should know

Unlock the power of Git with this essential guide! We cover the Git commands every developer must master to streamline their workflow and boost productivity. Whether you're a beginner or an experienced developer, this will help you understand key Git commands like clone, commit, push, pull, branch, merge, and more. Learn how to efficiently manage version control and collaborate on projects with ease. Don't miss out on these must-know Git tips that will take your development skills to the next level!

Git Commands



  1. git init
    • Initialize a new Git repository.
    • Example: Run this in an empty project folder to start version control.
  2. git clone <repo_url>
    • Clone an existing repository from a remote source.
    • Example: git clone https://github.com/user/repo.git to copy a project from GitHub.
  3. git status
    • Show the status of changes in the working directory and staging area.
    • Example: Run this to check which files have been modified or staged.
  4. git add
    • Add a specific file to the staging area.
    • Example: git add index.html to stage index.html for commit.
  5. git add .
    • Add all changes in the working directory to the staging area.
    • Example: Run this when you want to stage all modified and new files.
  6. git commit -m "message"
    • Commit the staged changes with a descriptive message.
    • Example: git commit -m "Fixed login issue" to save changes with a meaningful note.
  7. git commit --amend -m "new message"
    • Modify the last commit message.
    • Example: Run this if you made a typo in the previous commit message.
  8. git log
    • Show commit history.
    • Example: Use this to review past commits and their messages.
  9. git log --oneline
    • Show commit history in a compact format.
    • Example: Use this for a quick summary of commit history.
  10. git diff
    • Show differences between working directory and staging area.
    • Example: Run this to see what changes have been made before staging.
  11. git diff --staged
    • Show differences between the staged files and the last commit.
    • Example: Use this before committing to review staged changes.
  12. git branch
    • List all branches in the repository.
    • Example: Run this to check which branches exist in your project.
  13. git branch <branch_name>
    • Create a new branch.
    • Example: git branch feature-xyz to create a branch for a new feature.
  14. git checkout <branch_name>
    • Switch to a different branch.
    • Example: git checkout develop to move to the develop branch.
  15. git checkout -b <branch_name>
    • Create and switch to a new branch.
    • Example: git checkout -b bugfix-101 to create and switch to a new bugfix branch.
  16. git merge <branch_name>
    • Merge a branch into the current branch.
    • Example: git merge feature-xyz to merge changes from feature-xyz into the current branch.
  17. git rebase <branch_name>
    • Reapply commits on top of another base branch.
    • Example: git rebase main to move feature branch commits on top of main.
  18. git stash
    • Temporarily save changes that are not committed.
    • Example: Run this before switching branches when you have uncommitted changes.
  19. git stash pop
    • Reapply the latest stashed changes and remove them from the stash list.
    • Example: Use this to bring back previously stashed changes.
  20. git stash list
    • Show a list of stashed changes.
    • Example: Run this to check saved stashes.
  21. git stash drop
    • Delete the latest stashed change.
    • Example: Run this to remove an unwanted stash.
  22. git reset
    • Unstage a specific file from the staging area.
    • Example: git reset index.html to remove index.html from staging but keep changes.
  23. git reset --hard
    • Reset the working directory and staging area to the last commit.
    • Example: Run this if you want to discard all uncommitted changes.
  24. git reset --soft HEAD~1
    • Undo the last commit but keep changes in the staging area.
    • Example: Use this if you want to redo the last commit with a different message.
  25. git revert <commit_hash>
    • Create a new commit that undoes the changes from a specific commit.
    • Example: git revert abc123 to undo commit abc123 safely.
  26. git pull
    • Fetch and merge changes from a remote repository.
    • Example: git pull origin main to update the local branch with the latest remote changes.
  27. git fetch
    • Download changes from a remote repository without merging.
    • Example: Run this to check for remote updates before merging.
  28. git push
    • Push local changes to a remote repository.
    • Example: git push origin main to upload local commits to the main branch.
  29. git push -u origin <branch_name>
    • Push a branch to the remote repository and track it.
    • Example: git push -u origin feature-xyz to push a new branch and set tracking.
  30. git remote -v
    • List all remote repositories linked to the local repository.
    • Example: Use this to check remote connections.
  31. git remote add
    • Add a new remote repository.
    • Example: git remote add origin https://github.com/user/repo.git to link a GitHub repository.
  32. git remote remove
    • Remove a remote repository.
    • Example: git remote remove origin to delete a remote link.
  33. git tag <tag_name>
    • Create a new tag.
    • Example: git tag v1.0 to mark a version release.
  34. git tag -a <tag_name> -m "message"
    • Create an annotated tag with a message.
    • Example: git tag -a v1.0 -m "Version 1.0 release" to add a tag with a description.
  35. git show <tag_name>
    • Show details of a tag.
    • Example: git show v1.0 to see information about a tag.
  36. git cherry-pick <commit_hash>
    • Apply a specific commit from another branch.
    • Example: git cherry-pick abc123 to apply a single commit from another branch.