Live data from Hacker News

Show HN: Switch Git Users CLI

github.com

1–10 of 61 posts

Re: Show HN: Switch Git Users CLI

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

Re: Show HN: Switch Git Users CLI

#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 the usual gitconfig settings that apply, for example the [user] section...

Switching to the right directory thus automatically changes the settings.

Re: Show HN: Switch Git Users CLI

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

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.

Re: Show HN: Switch Git Users CLI

#8
Without using include in gitconfig:

  #!/usr/bin/env zsh
  case $1 in
  foo)
      git config user.name 'John Doe'
      git config user.email john@example.com
      git config user.signingKey 0xFFFFFFFF
      ;;
  bar)
      git config user.name 'Jane Doe'
      git config user.email jane@example.com
      git config user.signingKey 0xEEEEEEEE
      ;;
  baz)
      git config user.name 'My Dog'
      git config user.email dog@example.com
      git config user.signingKey 0xDDDDDDDD
      ;;
  *)
      echo "usage: git-user foo|bar|baz" >&2
      exit 1
      ;;
  esac
Done.

Btw probably want to add signingKey support.

Post reply on HN