Git

Common Git commands and workflows

Setup

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

Basics

git init                  # Initialise a new repo
git clone <url>           # Clone a remote repo
git status                # Show working tree status
git add <file>            # Stage changes
git commit -m "message"   # Commit staged changes

Branching

git branch                # List branches
git branch <name>         # Create a branch
git checkout <name>       # Switch to a branch
git checkout -b <name>    # Create and switch
git merge <branch>        # Merge branch into current
git branch -d <name>      # Delete a branch

Remote

git remote -v             # List remotes
git fetch                 # Download remote changes
git pull                  # Fetch and merge
git push                  # Push local commits
git push -u origin <branch>  # Push and set upstream

Undoing

git restore <file>        # Discard working changes
git restore --staged <file>   # Unstage
git reset HEAD~1          # Undo last commit (keep changes)
git revert <commit>       # Create a reverse commit

Company information:

Geeky Code Ltd
Company Number: 12200751