Version control is a must-have skill for any developer, and Git is by far the most popular tool in this space. Today, I took a deep dive into Git and learned all the essential commands that every developer should know.
Here’s a summary of what I learned—bookmark this blog if you want a cheat sheet for your future Git workflows!
Git Basics
1. Initialize a Repository
git init
Creates a new Git repository in your current folder.
2. Clone a Repository
git clone <repo_url>
Clones a remote repository to your local machine.
Working with Changes
3. Check Status
git status
Displays the state of the working directory and staging area.
4. Add Changes
git add <file_name>
git add .
Adds files to the staging area. Use .
to add all changes.
5. Commit Changes
git commit -m "Your message"
Saves the staged changes with a descriptive message.
Working with Branches
6. Create a Branch
git branch <branch_name>
7. Switch to a Branch
git checkout <branch_name>
8. Create and Switch (Shortcut)
git checkout -b <branch_name>
9. List Branches
git branch
10. Delete a Branch
git branch -d <branch_name>
Pushing and Pulling
11. Push to Remote
git push origin <branch_name>
12. Pull Latest Changes
git pull origin <branch_name>
History and Logs
13. View Commit History
git log
14. Show Changes
git diff
Undoing Changes
15. Undo Changes in File
git checkout -- <file_name>
16. Unstage a File
git reset <file_name>
17. Amend Last Commit
git commit --amend
Remote Repository
18. Add Remote Repo
git remote add origin <url>
19. View Remotes
git remote -v
Advanced Commands (Optional)
20. Rebase
git rebase <branch_name>
21. Stash Changes
git stash
22. Apply Stashed Changes
git stash apply
Summary
Learning Git can be overwhelming at first, but once you understand the basic commands, it becomes second nature. With these 20+ commands, I now feel more confident in handling any Git workflow — from initializing repositories to branching, committing, and syncing with remotes.
Top comments (0)