GIT Commands Every Developer Should Know
Git is one of the most powerful tools every developer uses — whether you’re working on solo projects or collaborating with a team. It helps you track changes, collaborate efficiently, and maintain clean version control. However, with so many commands available, it can be tricky to know where to start.
In this post, we’ll cover the most essential Git commands every developer should know — from basic setup to advanced branching.
1. Initialize a Repository
git initCreates a new Git repository in your current directory. This is the first step to start tracking your project.
2. Clone an Existing Repository
git clone <repository_url>Copies a remote repository (for example, from GitHub) to your local machine.
Tracking and Saving Changes
3. Check Repository Status
git statusDisplays which files are staged, unstaged, or untracked — essential for seeing what’s going on.
4. Add Files to Staging
git add <file_name>Adds specific files to the staging area.
Use git add . to add all modified files.
5. Commit Changes
git commit -m "Your commit message"Saves your staged changes with a message describing what you did. Example:
git commit -m "Fix login bug and update UI"6. View Commit History
git logDisplays a list of previous commits with their unique IDs and messages.
Working with Remote Repositories
7. Add a Remote Repository
git remote add origin <repository_url>Connects your local repo to a remote one (like GitHub or GitLab).
8. Push Changes to Remote
git push origin mainUploads your commits to the remote repository’s main branch.
9. Pull Latest Changes
git pullFetches and merges updates from the remote repository into your local branch.
Branching and Merging
10. Create a New Branch
git branch <branch_name>Creates a new branch — ideal for working on features without touching the main codebase.
11. Switch to a Branch
git checkout <branch_name>Moves you to a different branch. (You can also create and switch in one go with git checkout -b <branch_name>.)
12. Merge Branches
git merge <branch_name>Combines the specified branch into your current one — typically merging a feature branch into main.
Undoing Mistakes
13. Discard Local Changes (Unstaged)
git checkout -- <file_name>Reverts a file back to the last committed version.
14. Unstage a File
git reset <file_name>Removes a file from the staging area but keeps its changes in the working directory.
15. Revert a Commit
git revert <commit_id>Creates a new commit that undoes the changes made by a previous commit — safer than deleting history.
Bonus Tips
- Use
git stashto temporarily save changes without committing. - Use
git diffto compare changes between commits or branches. - Use
git tagto mark important versions (likev1.0).
Conclusion
Mastering these Git commands will make your workflow faster, cleaner, and more collaborative. Even though Git can feel intimidating at first, understanding these basics will cover 90% of what you’ll need in everyday development.
Pro Tip: The more you use Git, the more comfortable it becomes — so don’t be afraid to experiment and break things (that’s what version control is for!).
