DevOps, Misc

Boost Your Productivity with These 20 Useful Git Commands

Git is a powerful and versatile version control system that is widely used in software development projects. It allows developers to easily manage changes to their code, collaborate with others, and track their progress over time. However, with so many commands available, it can be overwhelming for beginners to know where to start. In this blog post, we’ll go through the top 20 most useful Git commands with examples.

  1. git init: Initializes a new Git repository in the current directory.
$ git init
  1. git clone: Clones an existing Git repository to a new directory.
$ git clone <repository-url>
  1. git add: Adds files to the staging area.
$ git add <file1> <file2>
  1. git status: Shows the current status of the working directory.
$ git status
  1. git commit: Commits changes to the repository.
$ git commit -m "Commit message"
  1. git push: Pushes changes to a remote repository.
$ git push <remote> <branch>
  1. git pull: Pulls changes from a remote repository.
$ git pull <remote> <branch>
  1. git branch: Shows the list of branches in the repository.
$ git branch
  1. git checkout: Switches to a different branch.
$ git checkout <branch>
  1. git merge: Merges changes from one branch into another.
$ git merge <branch>
  1. git log: Shows the commit history of the repository.
$ git log
  1. git diff: Shows the difference between two commits or between the working directory and the repository.
$ git diff <commit1> <commit2>
  1. git reset: Resets the current branch to a previous commit.
$ git reset <commit>
  1. git revert: Reverts a commit, creating a new commit that undoes the changes made by the original commit.
$ git revert <commit>
  1. git stash: Temporarily saves changes that are not yet ready to be committed.
$ git stash
  1. git tag: Tags a specific commit with a name.
$ git tag <tag-name> <commit>
  1. git remote: Shows the list of remote repositories.
$ git remote
  1. git fetch: Fetches changes from a remote repository without merging them.
$ git fetch <remote>
  1. git cherry-pick: Picks a specific commit from one branch and applies it to another branch.
$ git cherry-pick <commit>
  1. git blame: Shows who made changes to a file and when.
$ git blame <file>

These 20 Git commands are some of the most useful and commonly used commands in software development. While they may seem overwhelming at first, they become second nature with practice. Whether you are new to Git or an experienced user, mastering these commands will make your work much more efficient and productive.