When I asked for suggestions about note-taking apps back in May I wasn’t fully convinced I’d be able to stick with it, but nearly 6 months later it has probably been the thing I’ve been most consistent about. Anyways, here’s a rather short list of Git things off the ‘TIL’ list in my Logseq graph.
git add
git add -u
will stage changes to all tracked files and leave untracked ones alone.git add -N
will stage a file without any of its changes. You can treat that as an “intention” to create a file as well as making it easier to usegit diff
to see what is being added without needing the--cached
flag every time.
Git submodules
Probably the biggest pain in the ass in all of Git land. Every time I’ve had to use a submodule, I’ve disliked the experience. Here’s how to properly get rid of a submodule in case you’re switching to git-subrepo or a different solution.
git submodule deinit -f path/to/module
rm -rf .git/modules/path/to/module
git config -f .gitmodules --remove-section submodule.path/to/module
git add .gitmodules
git rm --cached path/to/module
In order, this
deinit
removes the checkout of the submodule and removes it from.git/config
- Deletes the bare repository Git creates of the submodule which is used to generate the actual checkout
- Edits your
.gitmodules
file to remove the submodule entry - Stages the changes to
.gitmodules
- Deletes the submodule fully from the index
At this point you can commit the changes and hopefully never deal with a submodule again :D
Git credential helpers
While trying to configure pass-git-helper to authenticate with my personal Git forge I ended up learning a bit about how Git interacts with credential helpers
Git credential helpers work via writing and reading from stdin and stdout which helped me debug an issue I was having with pass-git-helper. To get a credential helper to spit out the password, it needs to be called with get
as the first argument and pass in some basic key=value data. The interaction looks somewhat like given below, with <
indicating the stdin of the credential helper and >
indicating its stdout.
# for URL https://git.msfjarvis.dev/msfjarvis/super-private
$ pass-git-helper get
< protocol=https
< host=git.msfjarvis.dev
< path=msfjarvis/super-private
> protocol=https
> host=git.msfjarvis.dev
> username=msfjarvis
> password=hunter2