Live data from Hacker News

Show HN: Switch Git Users CLI

github.com

11–20 of 61 posts

Re: Show HN: Switch Git Users CLI

#11
post #5

Author here! I'm a freelancer working for multiple agencies at the moment. And One of the requirements was that I use the agency email for all commits. So I made this as a sugar for git config user.email whatever@gmail.com

https://git-scm.com/docs/git-config#_conditional_includes Is a lot easier then what you came up with.

Thanks. This is perfect but I also like the convenience of a quick switcher for any folder.

Re: Show HN: Switch Git Users CLI

#12
What's the point of writing this simple tool in js? I'd like to use it but I don't have npm everywhere (and I don't want to grab a huge tree of dependencies just for editing a couple of lines on a text file...)

Re: Show HN: Switch Git Users CLI

#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 config user.email "$(git config user.$1.email)"; :'
So given that I have created two users, e.g. personal and work I run:

  git identity work
in repos that need the work name/e-mail, and

  git identity personal
in the ones that are private.

Re: Show HN: Switch Git Users CLI

#14
post #6

This is a great looking tool. 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: [includeIf "gitdir:~/projects-private/**"] path = ./.gitconfig-private [includeIf "gitdir:~/projects-client/**"] path = ./.gitconfig-work Then in .gitconfig-private or .gitconfig-work I have all th…

Thanks for sharing this. This was what I was missing. Should've done proper research before building.

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.

Re: Show HN: Switch Git Users CLI

#17

Author here! I'm a freelancer working for multiple agencies at the moment. And One of the requirements was that I use the agency email for all commits. So I made this as a sugar for git config user.email whatever@gmail.com

I find that creating a separate user account on my system for each client works much better for this kind of thing than trying to configure every application with multiple identities.

Re: Show HN: Switch Git Users CLI

#18

What's the point of writing this simple tool in js? I'd like to use it but I don't have npm everywhere (and I don't want to grab a huge tree of dependencies just for editing a couple of lines on a text file...)

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.

Re: Show HN: Switch Git Users CLI

#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.

Re: Show HN: Switch Git Users CLI

#20
post #6

This is a great looking tool. 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: [includeIf "gitdir:~/projects-private/**"] path = ./.gitconfig-private [includeIf "gitdir:~/projects-client/**"] path = ./.gitconfig-work Then in .gitconfig-private or .gitconfig-work I have all th…

Thanks for sharing this. This was what I was missing. Should've done proper research before building. 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.

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.
Post reply on HN