This is an oldie but a goodie, for the simple fact that git is not only so common, but that knowledge of its ins and outs is valorized among programmers. I should be perfectly happy if someone read this entire page and the only lesson they took away was, ‘wow, git is a very poorly designed program.’
I am in the midst of teaching my web development students how to use git and - as is true every year - I am appalled at how convoluted it is. Git is the software equivalent of English.
I think it’s showing it’s age now. There are finally different commands for dealing with branches vs updating file contents.
git switch $branch will change your branch. git switch —create $branch will create a new one. git restore —source=$commit $file will update a file’s contents to the given commit.
git switch $branch
git switch —create $branch
git restore —source=$commit $file
Of course, git checkout is still there.
I realize there’s a lot to criticize about git here, but I read it in good faith and got the following out of it:
From git --help config:
git --help config
To avoid confusion and troubles with script usage, aliases that hide existing Git
commands are ignored
I don’t understand why Master Git said “there was no problem” though.
From git --help checkout:
git --help checkout
Updates files in the working tree to match the version in the index or the specified tree. If
no pathspec was given, git checkout will also update HEAD to set the specified branch as the
I think of it as “make the working tree correspond with a branch”, remembering that branches are just pointers to commits and thinking of HEAD as a special branch that points to the current branch.
I always think of git history as something that should be massaged to tell the story you want, not as a complete accounting of the facts. Branches are designed to be ephemeral and help you, not the narrative.
The -h / --help distinction isn’t very UNIXy, but it is convenient. git -h branch not working seems like a frustrating omission though.
git -h branch