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?

  • Re-enabling GIT control in copied project, in a new branch
  • Reopen a Pull Request
  • Exclude some project settings from version control system like Git, TFS
  • Multiple Projects in VisualStudio 2012 in one Solution using GIT
  • Jenkins job hangs on “git push origin branch” due to authentification
  • git pull: permission denied
  • Git subtree or Git Sub module for large resources?
  • Can I create a symbolic link automatically after git clone
  • How do I make git accept mode changes without accepting all text changes?
  • Listing each branch and its last revision's date in git
  • Why can't I install TortoiseGit on Windows 7?
  • git fetch insufficient permission for adding an object to repository database .git/objects?
  • 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.