Every Developer Should Know this 10 Git Commands

Adnan Kazi
3 min readApr 4, 2023

Git is an essential tool for developers who collaborate on code projects, whether they work in a team or alone. Git is a distributed version control system that helps developers track changes to code over time, revert to previous versions, and collaborate with others. However, some developers may feel overwhelmed by Git’s command-line interface, which can be challenging to learn at first. In this article, we will discuss ten essential Git commands that every developer should know.

  1. git init

The first step in using Git is to initialize a new repository. The git init command creates a new Git repository in the current directory. To initialize a new repository, navigate to the project directory in your terminal and type:

git init

2. git add

After you have initialized a new Git repository, you can start tracking changes to your project files. The git add command stages changes to your files so that Git can track them. To stage a file, navigate to the project directory and use the git add command followed by the file name. For example:

git add index.html

3. git commit

Once you have staged your changes, you can commit them to the Git repository. The git commit command creates a new commit that includes all of the changes you have staged. To create a new commit, use the git commit command followed by a commit message that describes the changes you have made. For example:

git commit -m "Added a new feature to the homepage"

4. git status

The git status command shows the current status of your repository. It displays information about which files have been modified, which files have been staged, and which files have not been tracked by Git. To see the current status of your repository, use the git status command:

git status

5. git log

The git log command displays a log of all the commits that have been made to the repository. It shows the commit message, the author, the date, and the unique commit hash. To see the log of commits, use the git log command:

git log

6. git branch

Git branches are a powerful feature that allows you to work on multiple versions of your project simultaneously. The git branch command creates a new branch or lists all existing branches. To create a new branch, use the git branch command followed by the name of the new branch:

git branch feature-branch

7. git checkout

The git checkout command allows you to switch between different branches. To switch to a different branch, use the git checkout command followed by the name of the branch you want to switch to:

git checkout feature-branch

8. git merge

The git merge command combines changes from one branch into another. To merge changes from one branch into another, navigate to the target branch and use the git merge command followed by the name of the source branch:

git checkout main
git merge feature-branch

9. git pull

The git pull command fetches changes from a remote repository and merges them into the local branch. To pull changes from a remote repository, use the git pull command:

git pull origin main

10. git push

The git push command uploads local changes to a remote repository. To push changes to a remote repository, use the git push command:

git push origin main

Conclusion: These are the ten essential Git commands that every developer should know. Although there are many more Git commands available, these ten commands will cover most of your daily Git workflow. With practice and patience, you’ll master Git and become a more productive and efficient developer.

--

--