Git Top Daily Life Usage Commands


In this blog, we’ll explore the top most popular Git commands that developers use on a daily basis.

1. git init

The git init command initializes a new Git repository in your project directory. It sets up the necessary infrastructure to start tracking changes.

Terminal
$ git init

2. git clone

To obtain a copy of a remote repository on your local machine, you can use the git clone command. This command creates a local clone of the repository, including all its branches and history.

Terminal
$ git clone https://github.com/websparrow-org/spring.git

3. git status

The git status command provides an overview of the current state, showing any modified, added, or deleted files.

Terminal
$ git status

4. git add

Before committing changes, you need to add files to the staging area using the git add command. It prepares them for inclusion in the next commit.

Add a single file:

Terminal
$ git add file.txt

Add multiple files:

Terminal
$ git add Test.java pom.xml ...

Add all files:

Terminal
$ git add .

5. git commit

The git commit command creates a new commit with the changes in the staging area and a descriptive message explaining the modifications made.

Terminal
$ git commit -m "Handled the NPE"

6. git pull

To fetch and merge changes from a remote repository into your current branch, you can utilize the git pull command. It updates your local branch with the latest commits from the remote repository.

Terminal
$ git pull origin master

7. git push

When you’re ready to share your local commits with the remote repository, the git push command comes into play. It pushes your changes to the designated remote repository.

Terminal
$ git push origin master

8. git branch

To view all the branches in your repository, you can execute the git branch command. It provides a list of branches and highlights the current branch.

Terminal
$ git branch

9. git checkout

The git checkout command allows you to switch between branches within the repository.

Terminal
$ git checkout feature/user-crud

10. git merge

To incorporate changes from one branch into another, the git merge command is essential. It merges the specified branch into the current branch, integrating the modifications.

Terminal
$ git merge feature/global-exception-handler

11. git fetch

The git fetch command retrieves the latest changes from a remote repository without merging them into your local branches. It is useful for reviewing changes before merging.

Terminal
$ git fetch origin

12. git log

The git log command displays a detailed log of all commits in your repository. It provides information such as commit hashes, authors, timestamps, and commit messages.

Terminal
$ git log

13. git diff

To view the differences between your working directory and the staging area, you can use the git diff command. It highlights the lines that have changed.

Terminal
$ git diff

14. git remote

When working with remote repositories, the git remote command is invaluable. It lists the remote repositories associated with your local repository.

Terminal
$ git remote -v

15. git reset

If you accidentally add files to the staging area, the git reset command allows you to unstage them, removing them from the staging area.

Terminal
$ git reset Test.java

References

  1. Getting Started with Git and Setup Development Environment
  2. Git Commands – Atlassian
  3. Git Commands- Git SCM

Similar Posts

About the Author

Atul Rai
I love sharing my experiments and ideas with everyone by writing articles on the latest technological trends. Read all published posts by Atul Rai.