GIT
Essential Git Commands
A quick reference for essential Git commands to manage repositories, branches, and commits effectively.
Create a New Repository | |
git init | |
git add . | |
git commit -m 'commit message' | |
git remote add origin [email protected]:username/repo.git | |
git push -u origin master | |
Clone a Repository | |
git clone [email protected]:username/repo.git | |
Pull changes from Remote Branch | |
git pull origin <branch> | |
Push changes from Remote | |
git push origin <branch> | |
Working with Local Changes | |
git status | |
git add . | |
git add -p <file> | |
git commit -m 'commit message' | |
Viewing History | |
git log | |
git log --oneline | |
git blame <file> | |
Branch & Merge | |
git branch | |
git branch -a | |
git checkout <branch> | |
git checkout -b <branch> | |
git merge <branch> | |
git merge --no-ff <branch> | |
Undoing Changes | |
git reset --hard HEAD | |
git reset --hard <commit_hash> | |
git checkout HEAD <file> | |
git revert <commit_hash> | |
Temporary Commits | |
git stash | Save modified and staged changes |
git stash list | List all stashes |
git stash pop | Write latest stash to working tree |
git stash apply | Apply latest stash to working tree |
git stash drop | Discard latest stash |
View Differences | |
git diff | View changes between the working tree and the index |
git diff <file> | View changes between the working tree and the index or a specific file |
git diff HEAD | View changes between the working tree and last commit |
Deleting Branches | |
git branch -d <branch> | Delete a local branch (if merged) |
git branch -D <branch> | Force Delete a local branch |
git push origin --delete <branch> | Delete a remote branch |
Configuration | |
git config --global user.name 'username' | |
git config --global user.name '[firstname lastname]' | |
git config --global user.email 'email' | |
