Cheat sheet
Git
Everything you need to keep your projects in Git and on GitHub: daily commands, branches, undoing mistakes and working with others.
- 28 entries
- 8 topics
1Set up once
- Your name and email
git config --global user.name "Your Name" git config --global user.email "you@example.com"- Default branch name
git config --global init.defaultBranch main
2Start a repository
- New project
git init- Copy an existing one
git clone https://github.com/user/repo.git- Connect to GitHub
git remote add origin https://github.com/you/repo.git git push -u origin main- -u remembers where to push next time
3Every day
- What changed
git status- Stage changes
git add file.c git add .- git add -p lets you pick parts of a file
- Commit
git commit -m "Add UART receiver"- Say what the change does, in a few words
- Send and get
git push git pull
4Looking at history
- Short history
git log --oneline --graph- Unstaged changes
git diff- Staged changes
git diff --staged- One commit
git show a1b2c3d- Who changed a line
git blame file.v
5Branches
- New branch
git switch -c add-fifo- Change branch
git switch main- Merge into main
git switch main git merge add-fifo- Delete merged branch
git branch -d add-fifo- List branches
git branch -a
6Undoing things
- Discard changes to a file
git restore file.c- Cannot be undone
- Unstage a file
git restore --staged file.c- Fix the last commit
git commit --amend- Only before you push it
- Undo a pushed commit
git revert a1b2c3d- Adds a new commit that reverses it: safe to share
- Put work aside
git stash git stash pop
7Ignore files
- .gitignore
build/ *.o *.vcd .venv/ .env- Never commit passwords, keys or large generated files
8Good habits
- Small commits
One change per commit- Easier to review and to undo
- Pull before you start
git pull- Fewer conflicts later
- README
What it is, how to run it, a screenshot- Recruiters read this first
ECEdge: free ECE roadmaps, tools and cheat sheets at ece-roadmap.pages.dev