- Published on
Git / GitHub Cheatsheet
- Authors

- Name
- seren-wib
Contents
A personal cheatsheet for when I get confused. Run the commands in a terminal after moving into the repository folder.
0. Basic Concepts
- Local: the files/repository on my computer
- Remote (remote, origin): the repository uploaded to GitHub
- Commit (commit): one snapshot that records changes
- stash: temporarily putting in-progress changes away in a "drawer"
1. Checking the Current State
git status # which files changed
git log --oneline -10 # the 10 most recent commits
git fetch # only fetches remote info (files don't change)
git log HEAD..@{u} --oneline # commits that are on the remote but not on mine
2. Pulling Without Losing Changes ★ (what I did on 2026-06-13)
When I have files being edited locally and the remote also has new commits. A plain git pull stops or is refused on overlapping files. The safe order:
# 1. Put local changes away in the drawer (-u also includes newly created untracked files)
git stash push -u -m "stash before pull"
# 2. Fetch the remote from the clean state
git pull --ff-only
# 3. Take the stashed changes back out
git stash pop
- If files overlap,
stash popproduces a conflict → go to section 3 below. - No data is lost. Even on a conflict, the stash stays in
git stash list.
3. Resolving Conflicts
When you open a conflicted file, it contains markers like these:
<<<<<<< Updated upstream
Remote (fetched side) content
=======
My local (stash) content
>>>>>>> Stashed changes
How to resolve:
- Keep only the content you want and delete the three marker lines yourself (
<<<,===,>>>) - If both sides are needed, keep both and delete only the markers
- Stage the cleaned-up file:
git add "path/to/file"
Delete vs modify conflict (one side deleted the file and the other edited it):
git rm "path/to/file" # when choosing deletion
# or
git add "path/to/file" # when choosing to keep it (the file stays)
Once all conflicts are cleaned up, empty the stash drawer:
git stash drop # delete the stash just popped
git stash list # check the remaining stashes
4. Committing and Pushing
git add . # stage all changes (or just "file name")
git commit -m "message" # commit
git push # upload to the remote (GitHub)
5. Undoing (When You Make a Mistake)
git restore "path/to/file" # discard edits and go back to the last commit's state
git restore --staged "path/to/file" # undo an add (changes are kept)
git stash list # list of stashed changes
git stash pop # take the most recent stash back out
git reset --hard HEAD # ⚠️ discards all local changes (cannot be undone, careful)
Frequently Used One-Line Summary
| What I want to do | Command |
|---|---|
| Check status | git status |
| Safely fetch remote changes | stash → git pull --ff-only → git stash pop |
| After resolving a conflict | Delete the markers, then git add |
| Commit | git add . → git commit -m "..." |
| Upload to GitHub | git push |
| Temporarily stash changes | git stash push -u |
| Take out what was stashed | git stash pop |