some git mistakes people have listed on Mastodon. the ones in bold are (anecdotally) more common
-
committing
- staging changes carefully, then running
git commit -a
git commit --amend
ing the wrong commit (eg thinking I've already committed some changes, but I haven't)- forgetting that I've already done a git push, and then doing another git commit --amend
- got confused about what repo/machine I was on and wrote wrong commit message
git commit -ammend
instead ofgit commit --amend
- committing with the wrong email address
- accidentally committing a large binary file and only noticing much later
- forgetting to add new source files before committing
- not committing frequently enough
git commit
instead ofgit commit --amend
- staging changes carefully, then running
-
rebase
- forgetting to put in a temporary tag before doing an interactive rebase.
- forgetting when to do
git rebase --continue
vsgit commit --amend
vsgit commit
during a rebase - rebasing a long history without squashing first, getting a new merge conflict for every commit and then losing track of which changes come from which branch.
- overambitious
git rebase --interactive
- tagging releases before i rebase instead of after.
- trying to recover from merge/rebase conflicts instead of backing away slowly and cherry picking my way to victory.
- switching from rebase updates to merge updates too soon
- squashing too much before merging
-
losing uncommitted changes
- losing uncommitted changes with
git checkout
orgit restore
- misunderstanding what
git reset --hard
does and losing work - 'git clean -fd' without first doing 'git add'
- losing uncommitted changes with
-
reset
- running
git reset
when I have uncommitted changes
- running
-
merge
- getting distracted in the middle of a merge, and then coming back to a half-merged mess
- getting distracted in the middle of a merge or rebase and later creating a new commit before having finished.
- committing a revert of a merge has messed me up in the past, because if you then try to re-merge the original work, the original work is already in history and has already been reverted.
- not noticing that a merge or rebase failed, charging on with new code, and later wondering why there are merge markers.
- branch of a branch, but I forget about it for a while and rebase the ‘middle’ from upstream without thinking about the implications. The ‘leaf’ has merge commits too though, and it takes a while to unwind (in the past, I’ve given up, copied the entire repo state to a temp dir, deleted the branch and recreate it again with a single commit by copying the dir back over)
- delete/rename conflicts. I had to checkout to a previous commit, copy a file manually, do the merge /rebase, and then reapply my changes by hand.
- incorrectly resolved merge conflicts
-
push/pull
- forgetting to pull before starting work (forget to pull the latest main, create a new branch, open a PR, immediate merge conflicts)
- accidentally pushing WIP commits to main
- pulling the wrong upstream branch into a local branch
- pushing to the wrong remote
- force pushing without having pulled
- cloning a repo with the wrong identity
- forgetting to push
-
wrong commit
- cherry picking wrong commit
-
wrong branch
- commiting to
main
instead of starting a new branch - committing in detached HEAD state & switching branches
- merging into the wrong branch
git branch -D
ing the wrong branch- typing
git branch NEW
instead ofgit checkout -b NEWBRANCH
and forgetting thatgit branch
doesn't actually check out the new branch - committing to the wrong branch
- commiting to
-
submodules
- updating submodules in the same repo on two computers.
- interrupting git during a submodule update --init which can leave repos with a branch checked out but all files missing.
git add external/repo/
when I meangit add external/repo
The first one adds all the files in the repo, the second makes a submodule.
-
stash
git add
-ing a bunch of stuff and then runninggit stash
without--keep-index
("git should have astash.keepIndex
configuration option that changes that behavior to be the default")- pop something old with
git stash
, screw up the merge, lose it forever (prevention: usegit stash apply
) - stashing changes and then forgetting about them and having to redo the work
- forgetting to
--include-untracked
on agit stash
-
other
- deleting
.git
- pressing Ctrl-C to cancel a long-running sync/checkout/etc. and getting into some weird transient state
- Reverting no changes (because I don't know, used wrong hash?) or reverting then trying to pull and somehow ending up with my changes anyway?
- not creating a .gitignore file early enough and committing junk
- deleting
-
mysterious
- I don't know what I did, but git once complained (IIRC) that “master” was an ambiguous name
- Trying to squash a subset of a bunch of commits into one so it can be merged, and the local copy of the repo gets corrupted
- in a really big repo: fetching so many temporary branches over and over that the GC stops working
- I accidentally committed and pushed a bunch of images before double-checking that LFS was set up to track them correctly. Had to rebuild entire commit graph and force push everything.