<< back to Guides
Git Quick Guide
1. Setting Up Git
- Before you start using Git, configure your identity:
git config --global user.name "Your Name"
git config --global user.email "your.email@example.com"
- Check your configuration:
git config --list
2. Working with a Repository
- Clone a Repository
git clone <repository-url>
- Check Repository Status
git status
- Add Files to Staging
git add <file-name>
# Or add all changes
git add .
- Commit Changes
git commit -m "Your commit message"
3. Branching and Merging
- Create a New Branch
git branch <branch-name>
- Switch to a Branch
git checkout <branch-name>
- Create and Switch to a Branch
git checkout -b <branch-name>
- Merge Branches
git merge <branch-name>
4. Syncing with Remote
- Push Changes
git push origin <branch-name>
- Pull Changes
git pull origin <branch-name>
- Set Remote Repository
git remote add origin <repository-url>
5. Undoing Changes
- Discard Unstaged Changes
git checkout -- <file-name>
- Unstage Changes
git reset <file-name>
- Undo the Last Commit (Keep Changes)
git reset --soft HEAD~1
- Undo the Last Commit (Discard Changes)
git reset --hard HEAD~1
6. Viewing Logs and History
- Show Commit History
git log
- Show Changes in Commit History
git log -p
- Show Graphical History
git log --oneline --graph --decorate --all
Git Cheatsheet
Command | Description |
---|---|
git config --global |
Configure global username/email |
git init |
Initialize a repository |
git clone <url> |
Clone a repository |
git status |
Show the working directory status |
git add <file> / git add . |
Add file(s) to the staging area |
git commit -m "<message>" |
Commit staged changes |
git branch |
List branches |
git branch <branch-name> |
Create a new branch |
git checkout <branch-name> |
Switch to a branch |
git checkout -b <branch-name> |
Create and switch to a branch |
git merge <branch-name> |
Merge a branch into the current branch |
git pull origin <branch-name> |
Pull updates from a remote branch |
git push origin <branch-name> |
Push changes to a remote branch |
git reset <file> |
Unstage a file |
git reset --soft HEAD~1 |
Undo last commit but keep changes |
git reset --hard HEAD~1 |
Undo last commit and discard changes |
git log |
Show commit history |
git log --oneline --graph --all |
Show graphical commit history |
For more advanced Git commands, consult the Git documentation.
<< back to Guides