Blog Logo

27 Sep 2023 ~ 4 min read

All the Git Commands You Need to Know


Git is a powerful version control tool that plays a crucial role in modern software development. Familiarizing yourself with essential Git commands is fundamental to effectively manage your source code and collaborate with other developers. In this guide, we will explore all the Git commands you need to know to become an expert.

Contents:

1. git init

The first step in versioning your project with Git. This command initializes a new Git repository in your directory.

git init

2. git clone

Use this command to create a local copy of an existing Git repository.

git clone <repository_URL>

3. git add

Add changes to your upcoming commit. You can specify individual files or use git add . to add all modified files.

git add <file_name>

4. git commit

Record changes in your repository with a descriptive message.

git commit -m "Commit message"

5. git pull

Update your local repository with changes from the remote repository.

git pull

6. git push

Send your local changes to the remote repository.

git push

7. git branch

List all branches in your repository and show the currently checked-out branch.

git branch

8. git checkout

Switch between branches or create a new branch.

git checkout <branch_name>

9. git merge

Combine changes from one branch into another.

git merge <branch_name>

10. git log

View the commit history of the repository.

git log

11. git stash

Temporarily stash uncommitted changes.

git stash

12. git reset

Undo changes in the repository.

git reset <commit_hash>

13. git remote

List configured remote repositories.

git remote -v

14. git fetch

Download information from the remote repository but do not automatically merge.

git fetch

15. git rebase

Rearrange commits for a cleaner timeline.

git rebase <branch_name>

16. git tag

Mark commits for specific versions of your project.

git tag <tag_name>

17. git status

Check the current state of your repository, including modified and untracked files.

git status

18. git diff

Display the differences between files in your working directory and the staging area.

git diff

19. git remote add

Add a new remote repository to your Git configuration.

git remote add <remote_name> <remote_URL>

20. git remote remove

Remove a remote repository from your Git configuration.

git remote remove <remote_name>

21. git fetch

Update remote repository information and download changes but do not automatically merge.

git fetch

22 git rebase -i

Perform an interactive rebase to rearrange, edit, or merge commits.

git rebase -i <commit_hash>

23. git cherry-pick

Apply a specific commit from one branch to another.

git cherry-pick <commit_hash>

24. git log --graph

Visualize the commit history graphically, showing branches.

git log --graph

25. git clean

Remove untracked files from the working directory.

 git clean -n # Show files to be removed (dry run mode)
 git clean -f # Remove untracked files (with caution!)

26. git submodule

Manage Git submodules within your main repository.

git submodule add <submodule_URL> <local_path>

This guide provides a comprehensive overview of Git commands that are essential for any developer. As you advance in your Git journey, you can explore more advanced commands and branching strategies. However, with these basic commands, you are ready to start effectively managing your source code.

Remember that consistent practice is the key to mastering Git. So, start experimenting with these commands in your own projects and see how they can enhance your efficiency in software development.


Headshot of Francisco Inoque

Hello, I'm Francisco Inoque, an experienced Back-End Developer with expertise in Node.js, Go, and Python. I thrive on solving complex development challenges and am eager to contribute to innovative projects. Let's connect and discuss how I can help you achieve your goals efficiently!