Essential Git Commands
10 Essential Git Commands Every Developer Must Know: Complete Cheat Sheet with Branching, Merging, and Remote Workflows
Master Git with this complete guide to 10 essential commands including init, clone, commit, branch, merge, rebase, and remote operations. Perfect for beginners and reference.
Git is the backbone of modern version control. Whether you're a beginner or need a refresher, these 10 commands will cover 90% of your daily needs.
1. git init
Initialize a new Git repository in your project folder.
git init
2. git clone
Copy an existing repository from GitHub or another remote.
git clone https://github.com/user/repo.git
3. git add
Stage changes for commit. Use . to stage all.
git add filename.py
git add .
4. git commit
Save staged changes with a message.
git commit -m "Add login feature"
5. git status
See which files are staged, modified, or untracked.
git status
6. git log
View commit history. Add --oneline for compact view.
git log --oneline
7. git branch
List branches, create new ones, or delete.
git branch # list
git branch feature # create
git branch -d feature # delete
8. git checkout / git switch
Switch branches or restore files.
git checkout main
# or newer syntax:
git switch main
9. git merge
Combine changes from one branch into another.
git checkout main
git merge feature
10. git pull & git push
Sync with remote repository.
git pull origin main
git push origin main
Practice these commands daily and version control will become second nature.
Comments
Post a Comment