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