Skip to main content

GitHub

Use this as a quick reference for everyday Git and GitHub work: checking status, creating branches, committing changes, syncing with remote, and fixing common mistakes.

Setup

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

Check your config:

git config --list

Start A Repository

Create a new Git repository:

git init

Clone an existing GitHub repository:

git clone https://github.com/username/repository.git

Add a remote origin:

git remote add origin https://github.com/username/repository.git

Check remotes:

git remote -v

Daily Workflow

Check what changed:

git status

See file differences:

git diff

Stage one file:

git add path/to/file

Stage all changes:

git add .

Commit staged changes:

git commit -m "Describe the change"

Push to GitHub:

git push

Pull latest changes:

git pull

Branches

List branches:

git branch

Create and switch to a branch:

git switch -c feature/my-change

Switch branches:

git switch main

Push a new branch:

git push -u origin feature/my-change

Delete a local branch:

git branch -d feature/my-change

Sync With Main

Update local main:

git switch main
git pull

Bring main into your branch:

git switch feature/my-change
git merge main

Undo Common Mistakes

Unstage a file:

git restore --staged path/to/file

Discard changes in a file:

git restore path/to/file

Edit the last commit message:

git commit --amend -m "Better commit message"

See recent commits:

git log --oneline --decorate --graph -10

Pull Requests

Typical pull request flow:

  1. Create a feature branch.
  2. Commit and push your work.
  3. Open a pull request on GitHub.
  4. Request review.
  5. Merge after checks pass.

Useful commands:

git status
git switch -c feature/name
git add .
git commit -m "Add feature"
git push -u origin feature/name

Quick Fixes

If Git says your branch has no upstream:

git push -u origin your-branch-name

If you want to see who changed a line:

git blame path/to/file

If you want to temporarily save unfinished work:

git stash
git stash pop

Use short, specific commit messages:

Add GitHub cheat sheet
Fix guides redirect
Update PaddleOCR deployment notes

Avoid vague messages:

changes
update
fix