Live data from Hacker News

Show HN: Switch Git Users CLI

github.com

41–50 of 61 posts

Re: Show HN: Switch Git Users CLI

#41
post #19
post #13

I found this user management strategy somewhere, and it's been working great for me: git config --global --unset user.name git config --global --unset user.email git config --global --unset user.signingkey git config --global user.useConfigOnly true git config --global user. .name " " git config --global user. .email " " git config --global alias.identity '! git config user.name "$(git config user.$1.name)"; git conf…

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.

Git has conditional includes based on path[1]. My configuration is like:

On ~/.gitconfig

  [user]
    name = personal
    email = personal@example.com

  [includeIF "gitdir:~/workspace/"]
    path = ~/work.gitconfig

Then on ~/work.gitconfig

  [user]
    name = workname
    email = work@example.com
[1] https://git-scm.com/docs/git-config#_conditional_includes

Re: Show HN: Switch Git Users CLI

#42
post #13

I found this user management strategy somewhere, and it's been working great for me: git config --global --unset user.name git config --global --unset user.email git config --global --unset user.signingkey git config --global user.useConfigOnly true git config --global user. .name " " git config --global user. .email " " git config --global alias.identity '! git config user.name "$(git config user.$1.name)"; git conf…

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.

Re: Show HN: Switch Git Users CLI

#43
post #13

I found this user management strategy somewhere, and it's been working great for me: git config --global --unset user.name git config --global --unset user.email git config --global --unset user.signingkey git config --global user.useConfigOnly true git config --global user. .name " " git config --global user. .email " " git config --global alias.identity '! git config user.name "$(git config user.$1.name)"; git conf…

[deleted]

Re: Show HN: Switch Git Users CLI

#44
post #13

I found this user management strategy somewhere, and it's been working great for me: git config --global --unset user.name git config --global --unset user.email git config --global --unset user.signingkey git config --global user.useConfigOnly true git config --global user. .name " " git config --global user. .email " " git config --global alias.identity '! git config user.name "$(git config user.$1.name)"; git conf…

> git config --global alias.identity '! git config user.name "$(git config user.$1.name)"; git config user.email "$(git config user.$1.email)"; :'

Why `; :` at the end?

Re: Show HN: Switch Git Users CLI

#45
post #44
post #13

I found this user management strategy somewhere, and it's been working great for me: git config --global --unset user.name git config --global --unset user.email git config --global --unset user.signingkey git config --global user.useConfigOnly true git config --global user. .name " " git config --global user. .email " " git config --global alias.identity '! git config user.name "$(git config user.$1.name)"; git conf…

> git config --global alias.identity '! git config user.name "$(git config user.$1.name)"; git config user.email "$(git config user.$1.email)"; :' Why `; :` at the end?

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.

Re: Show HN: Switch Git Users CLI

#46
post #37
post #35

Earlier quoted context omitted.

So, not a 20 line bash script and at least two big dependencies. Sounds a lot like what you were poking fun at.

> at least two big dependencies Awk (a fraction of busybox’s 2.1 MBs) is a “big dependency”‽ Or maybe you’re saying git is‽ Edit: quote

Haha ok ok. Awk as a “big” dependency is hyperbole (:

I really am interested in what it would take to pull this off with bash. I may try it myself...

Re: Show HN: Switch Git Users CLI

#47
post #18

Earlier quoted context omitted.

I suspect it was written in JS because that was the author’s language of choice. There are lots of ways to manage git identities and this seems like a decent utility for web devs who already have node installed and don’t care to manually edit config files.

Of course, but my point is that these kind of tools are of general interest, and most programmers are not web developers.

Javascript is a general interest language imo.

Re: Show HN: Switch Git Users CLI

#48
You can have a per-project git config, which to me is a more convenient solution.

For my work repo I configure the repo to use my work identity. For my personal repos I use my personal identity.

I do not need to switch identities when using the same repo.

Doing this, you only setup your identity once per repo not every time, which is safer/less error prone. i.e.: you wont leak your work email on github by accident.

Re: Show HN: Switch Git Users CLI

#49
post #19

Earlier quoted context omitted.

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.

Git has conditional includes based on path[1]. My configuration is like: On ~/.gitconfig [user] name = personal email = personal@example.com [includeIF "gitdir:~/workspace/"] path = ~/work.gitconfig Then on ~/work.gitconfig [user] name = workname email = work@example.com [1] https://git-scm.com/docs/git-config#_conditional_includes

Woah, this is neat!
Post reply on HN