Skip to content

Instantly share code, notes, and snippets.

@jvns

jvns/mistakes.md Secret

Last active March 27, 2024 19:51
Show Gist options
  • Star 24 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save jvns/f7d2db163298423751a9d1a823d7c7c1 to your computer and use it in GitHub Desktop.
Save jvns/f7d2db163298423751a9d1a823d7c7c1 to your computer and use it in GitHub Desktop.

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 --amending 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 of git 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 of git commit --amend
  • rebase

    • forgetting to put in a temporary tag before doing an interactive rebase.
    • forgetting when to do git rebase --continue vs git commit --amend vs git 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 or git restore
    • misunderstanding what git reset --hard does and losing work
    • 'git clean -fd' without first doing 'git add'
  • reset

    • running git reset when I have uncommitted changes
  • 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 -Ding the wrong branch
    • typing git branch NEW instead of git checkout -b NEWBRANCH and forgetting that git branch doesn't actually check out the new branch
    • committing to the wrong branch
  • 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 mean git 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 running git stash without --keep-index ("git should have a stash.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: use git stash apply)
    • stashing changes and then forgetting about them and having to redo the work
    • forgetting to --include-untracked on a git 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
  • 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment