I find it much easier to use direnv and set GIT_AUTHOR_EMAIL in each of ~/work/.envrc and ~/personal/.envrc No need to reconfigure every repo this way.
I do the same. Also remember the following keyword if you use nested .envrc files: source_up
If you don't use this in any nested envrc files, the settings don't carry over which means your git settings are not maintained. It is kind of an escape hatch as the parent files are not verified in the same way normal envrc files are, but I have found the trade off to be worth it
Nice! I was thinking of something like this recently, but decided instead to completely divorce personal and work projects. It’s nice to close the work laptop and go open the personal laptop knowing it’s impossible to cross the streams, as well as for the ritual.
I'm not entirely sure, but `:` means "true" in bash, and if I omit it, something like this happens:
$ git config alias.foo '! echo "$1";'
$ git foo bar
bar
echo "$1";: bar: command not found
Whereas if I end with `; :` then it works as expected:
$ git config alias.foo '! echo "$1"; :'
$ git foo bar
bar
It seems to execute the last argument (`bar`) as a command without the `:` at the end, and I don't have a `bar` command on my PATH so it angrily fails with exit code 127. If it instead executes `:` however, that will make it happily exit with 0.
It seems to be a Git alias quirk, but I may be incorrect here.
What I have been doing by hand for some time is putting code for different customers in different directories and having a conditional in `~/.gitconfig` to determine what config applies there:
The CLI tool looks very great indeed and handy when you keep all the projects in the same top-level directory, or need to be able to change identity while in the same repository.
However, your .gitconfig setup is (for me) way nicer as I already have things split up by GitHub organization, and now my identity can change without having to do anything at all.
So thanks for sharing that, had no idea it was possible.
I think a tool that has a similar UX as your is handy if a person don't care or want to memorise the gitconfig documentation to figure this out. Which, I think, is true even for most of the developers. I have found this one out by a coincidence myself.
This is the approach that works very well for me. Especially since I keep my repos cloned into a directory structure inspired by "go get" using https://github.com/grdl/git-get
various permutations of which were posted an hour ago and are currently higher than this comment, so I’m confused why multiple people asked to see them ~30½ minutes ago
I asked because none of the posted permutations offer the same feature set. Specifically, the nice thing about this utility (and reason for the dependencies) is interactive adding and selecting of identities. If this can replicated in bash, I am legitimately interested in seeing it, 20 lines or not.
!!!
which not only covers the identity scenario but the whole configuration of git, which can be indeed very different from repo to repo, from company to company
On ~/.gitconfig
Then on ~/work.gitconfig [1] https://git-scm.com/docs/git-config#_conditional_includesIf you don't use this in any nested envrc files, the settings don't carry over which means your git settings are not maintained. It is kind of an escape hatch as the parent files are not verified in the same way normal envrc files are, but I have found the trade off to be worth it
But: does this edit a file that can appear in .gitignore or are you uploading this to affect all your collaborators?
Why `; :` at the end?
It seems to be a Git alias quirk, but I may be incorrect here.
Deleted Comment
What I have been doing by hand for some time is putting code for different customers in different directories and having a conditional in `~/.gitconfig` to determine what config applies there:
Then in .gitconfig-private or .gitconfig-work I have all the usual gitconfig settings that apply, for example the [user] section...Switching to the right directory thus automatically changes the settings.
However, your .gitconfig setup is (for me) way nicer as I already have things split up by GitHub organization, and now my identity can change without having to do anything at all.
So thanks for sharing that, had no idea it was possible.
I'd still think the cli could be useful in some situations. but I agree with others about how big this had to be because I used node.
various permutations of which were posted an hour ago and are currently higher than this comment, so I’m confused why multiple people asked to see them ~30½ minutes ago
Btw probably want to add signingKey support.
Deleted Comment