a git cheat sheet

really appreciated everyone's suggestions on the previous thread! https://social.jvns.ca/@b0rk/112276852440106066

I only included things that I actually do in the cheat sheet (with a couple of exceptions like `git push -u`, which I only don't use because I have `push.autoSetupRemote true` configured) but there are a lot of other useful-looking tips in that thread that I don't personally use

Julia Evans (@[email protected])

Attached: 1 image working on a draft of a git cheat sheet, what's missing? most interested in relatively "basic" things in git that you always forget how to do. Right now I think the push/pull section is by far the weakest

Mastodon
the only other things in this cheat sheet that I personally don't use are `git switch` and `git restore`, which I actually think seem like great choices (the fact that `git checkout THING` just GUESSES if you want to switch to a branch or restore an old version of the file is kind of scary! git switch doesn't do that! and git checkout's syntax is just really weird!), but I'm used to `git checkout` and it doesn't cause me a lot of problems so I haven't been motivated to change my ways

@b0rk

> so I haven't been motivated to switch

I see what you did there

@gsuberland @b0rk
😁 👍
I am going to try (to) `switch`.
It sounds sound.
@b0rk I just made the turn to git switch in the last 6 months or so. Old habits are hard to kill, but what motivated me is writing a CLI tool for my team that does some git stuff, and I wanted it to be very transparent about what it did so I have it print out what it is doing, and so went with "switch." Not that people actually pay any attention to the tool's output anyway, but I like to pretend people read and that I'm being helpful 🙂
@b0rk This has been my experience too. “git-checkout does seven different things, it stinks” “okay, we’ve made dedicated commands for all the things you used to use checkout for!” “…oh, turns out I learned the seven things and breaking those habits would be hard”
@b0rk I'm at `git switch -c` sometimes, but git checkout for everything else. Also, `switch -c` is often baked into some alias as in the projects I work on, there tends to be some common prefix to most of my branch names.
@b0rk These are actually the two commands I immediately switched to, when they were introduced.
Can't even remember when I used checkout the last time 🤔🤗

@b0rk It's the same for me.

Even moreso that I have a convenient alias 'co' for it (and 'ci' for commit), and I would need to figure out similarly short aliases for switch and restore (sw and rs maybe?)

@b0rk I use git switch -C mybranch to automatically switch to the branch and reset it so that it's current. But when I want to reset a file back to what's in the repo, git checkout -- /path/to/file.

Guess I only made it halfway to the less overloaded commands 😂

@dade
That's the opposite of what I do. I use restore because git warned me to do so when I used the usual checkout. However creating or changing braches I still do with checkout   

When ever I have to push or pull I do that with remote and branch. I stopped using git push -u, as it made it too easy for me to keep pushing to wrong branches, like main in stead of feature or stupid stuff like that.
@b0rk

@b0rk I learnt about git switch from that previous thread!

I’ve adopted it myself now, because if I’m ever working with a fit newby, it’s going to be much easier to explain.

Also I feel that if git can improve, then so can I!

@b0rk I've been using switch and restore for a while now, and I now use checkout only to grab files from other commits. The main reason for me to switch was: they are more expressive and since I often had to explain to people how to git, I wanted te help others understand by using clearer commands. Not sure if that worked out, but I'm not going back.
@b0rk Am-I blind or is `git bisect` missing (I would have expected to find it in the archeology section)? Other than that it's a fantastic cheat sheet.
@robinm i don’t really use bisect so i left it out
@b0rk @robinm I never used it either, until I did. Once you‘ve seen the magic, you can’t imagine life without it. 😉
@b0rk @robinm Here’s what made it „click“ for me: had a bug in a big festure branch, wrote a passing test on main and rebased feature to main to get a failing test on feature. Now I could just run a single command to identify the bug automatically.
@b0rk I’m getting used to this happening to me more and more. The old process is ingrained in muscle memory so much that the new and improved one remains unused even after I finally become aware that it exists.

@b0rk Great work.

Down the road, I hope to find a git glossary that explains terms like "stage", "rebase", "tracking", and being "in" a branch.

@b0rk `git commit -m "message" -m"another line" -m"yet another line"` rocks.
@hrw @b0rk I really like this as git commit -m "subject line of message" --edit. When my ADHD is being particularly obnoxious I'm fairly likely to lose track of what I was working on and in which window if I'm interrupted, and when I find it again it's nice to have it tell me what I was supposed to be writing a commit message about.

@vathpela @b0rk Then I suggest adding "-v" to show patch in editor as well.

Allows to have a look at commit.

@b0rk this owns. if i still worked in an office i'd want it on a poster haha
@b0rk I'd like to add one more way of referring to a commit: `:/i\ fixed\ the\ thing` - matches the most recent ancestor commit where the message matches the regex `/i fixed the thing/`!

@b0rk maybe it's just me, but somehow I missed a short mention of "git diff" or a pointer to the "diff staged/unstaged changes" section in "know where you are" (or maybe in "prepare to commit"?), as that will show you what you are about to commit – which is usually what I really want to do to prevent doing something stupid. But as I said, maybe that's just me.

[Edit: or maybe move the "diff staged/unstaged changes" between "know where you are" and "prepare to commit"?]

@b0rk Yea, that's the reference card I've been looking for!
@b0rk
Maybe add a version/revision date so when I see this again I can tell whether it's the same or has been updated.
@b0rk Showing a commit history and rebase using little icons on the commits is such a good idea!
@b0rk this is excellent, thanks.
@b0rk
And this right here, it why I have no use for git.
Who has time for this?
@b0rk A-mazing. Had most of my working knowledge and then some.
@b0rk I need this as a laptop sticker, or on a drinks mat! Awesome cheat sheet!

@b0rk I started looking for this poster on your website, and at least I found the bingo card.

https://wizardzines.com/comics/git-discussion-bingo/

git discussion bingo

wizard zines
@foolishowl here's a link, I'm not totally confident that it'll print correctly though so I'm not sharing it widely yet https://wizardzines.com/git-cheat-sheet.pdf
Thank you so much @b0rk! Now if only I can find my printer…

@b0rk Sorry if this is already covered and I'm being obtuse, but if there a link to a text version of this somewhere? (I'm only asking because it seems useful for accessibility.)

Another slightly weird but related question: This seems useful and I'd like to post it somewhere at work. Other than crediting you by name, is there other information that should accompany it (a link, a license, or anything)? (And obviously if you object to reposting please say so.)

@internic you can link to https://wizardzines.com for now! there will be a text version eventually
wizard zines

wizard zines
@b0rk for unstaging everything, I usually use just 'git reset' instead of 'git reset HEAD'. I'm not sure what the difference is, if any.

@b0rk no way! I just recorded a git intro for some friends and will send them this.

Here’s my feeble attempt at being nearly as useful as your zines are! https://youtu.be/3B7qxN48hro?si=7IGYCw_sPvE6yN0Z

Git For Beginners: The 7 or so commands I use on a daily basis

YouTube
@b0rk geat sheet, giteat sheet
@b0rk Just gonna yoink this for my personal documentation folder lol
@b0rk I love the style and how condensed and concise this is... thank you!!
❤️ ❤️❤️
@b0rk as usual, a great read! It's impressive how you can summarize and visually structure the most important points, thank you so much!
@b0rk
After using git for over 15 years, I still find useful things to learn about it (git log -S).

Thanks!
@jpmens
@b0rk Would you mind adding "git add -u" to put in the staged area all modified tracked files?
Julia Evans (@[email protected])

really appreciated everyone's suggestions on the previous thread! https://social.jvns.ca/@b0rk/112276852440106066 I only included things that I actually do in the cheat sheet (with a couple of exceptions like `git push -u`, which I only don't use because I have `push.autoSetupRemote true` configured) but there are a lot of other useful-looking tips in that thread that I don't personally use

Mastodon
@b0rk a very good one!
One thing I am missing, that is helpful every once in a while is bisect… to search for a bug that has appeared with a certain version, and you want to find the change that caused it.

@b0rk $ git branch --sort=-commiterdate
fatal: unknown field name: commiterdate
$ git branch --sort=commiterdate
fatal: unknown field name: commiterdate

Hmm, something is wrong.

@b0rk One of my best friends who doesn't work in tech just asked if I could help them better understand git, and I immediately thought of this post. Thank you!! 💖