How to set different and for each Git branch?

Suppose I am using a shared computer account and working on a repository with multiple branches, each branch developed by a different user on that same computer account. It would be helpful to not have to switch the and every time a different user uses the computer to make commits to the repository.

How do I set a different and for each branch?

  • In git, how do I sync my tags against a remote server?
  • How to avoid “Merge branch 'master' of ssh://”
  • Got an error while running “npm install” on angular-phonecat directory
  • Git check custom rules
  • Prevent pull/push from an obsolete Git repo and redirect to a new one
  • Is there a way to do “git checkout” and *force* the argument to be interpreted as a branch name?
  • .gitignore exclude folder with files but include subdirectory
  • msys git and long paths
  • Cannot continue git rebase
  • Git pull into wrong branch
  • Git: how to clone another repository automatically after git clone
  • How to pull while deployment in ansible
  • 2 Solutions collect form web for “How to set different and for each Git branch?”

    The usual approach is to:

    • not rely on a local configuration to the repo
    • rely only on the global configuration (the one in $HOME/.gitconfig)

    That way, each user naturally has his/her own whenever he/she does any commit in a shared repo.

    If you really need to only update a branch per user, you could add a pre-commit hook making sure the right branch is about to be committed.

    If you are using the same computer account:

    a/ don’t 😉 It is not a best practice to share account
    b/ setup an alias (one per user) which would setup that config

    One approach that might work is:

    • use git worktree to get one folder per branch (instead of cloning your all repo multiple times)
    • change your prompt in order to set the right (environment variable GIT_AUTHOR_NAME) and (GIT_AUTHOR_EMAIL): see “Set environmental variables in a particular directory”

    Make a clone for each of you. Run git config --local xxx and git config --local xxx@yyy.zz in each clone. --local can be omitted since it’s the default.

    But why not create an account for each of you in the same computer?

    Git Baby is a git and github fan, let's start git clone.