<< back to Guides

Git Quick Guide

1. Setting Up Git

git config --global user.name "Your Name"
git config --global user.email "your.email@example.com"
git config --list

2. Working with a Repository

git clone <repository-url>
git status
git add <file-name>
# Or add all changes
git add .
git commit -m "Your commit message"

3. Branching and Merging

git branch <branch-name>
git checkout <branch-name>
git checkout -b <branch-name>
git merge <branch-name>

4. Syncing with Remote

git push origin <branch-name>
git pull origin <branch-name>
git remote add origin <repository-url>

5. Undoing Changes

git checkout -- <file-name>
git reset <file-name>
git reset --soft HEAD~1
git reset --hard HEAD~1

6. Viewing Logs and History

git log
git log -p
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