Skip to content
This repository has been archived by the owner on Mar 11, 2021. It is now read-only.
/ multi-user-git-hook Public archive

DEPRECATED: use Git hook to set git user info based on directory name.

License

Notifications You must be signed in to change notification settings

vcrx/multi-user-git-hook

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

multi-user-git-hook

DEPRECATED: Switch git user based on the name of the directory.

as @crea1 said in stackoverflow:

As of git version 2.13, git supports conditional configuration includes. In this example we clone Company A's repos in ~/company_a directory, and Company B's repos in ~/company_b.

In your .gitconfig you can put something like this.

[includeIf "gitdir:~/company_a/"]
  path = .gitconfig-company_a
[includeIf "gitdir:~/company_b/"]
  path = .gitconfig-company_b

Example contents of .gitconfig-company_a

[user]
name = John Smith
email = [email protected]

Example contents of .gitconfig-company_b

[user]
name = John Smith
email = [email protected]

setting git init template

TEMPLATE DIRECTORY Files and directories in the template directory whose name do not start with a dot will be copied to the $GIT_DIR(default: .git) after it is created.

git-init Documentation

The files which are copied from the template directory are placed in your GIT_DIR which defaults to the .git directory under your repo's root directory.

so we can put hooks in the template dir, and it will be copied to the newly created projects.

mkdir -p ~/.config/git/template/hooks
git config --global init.templateDir ~/.config/git/template

put hook file

first of all, pls read: githooks Documentation

cp -i pre-commit.py ~/.config/git/template/hooks/pre-commit

then next time you create a git project, the hook will be active.

set email

the key has means $(pwd) has $(value), for example, ~/0Workspace/multi-user-git-hook has 0Workspace.

[multi "ant"]
	has=0Ant
	user-email[email protected]
	user-name=xx
	user-signingkey = xxxx
[multi "gmail"]
	has=0Workspace
	user-email = [email protected]
	user-name = xxxxxx
	user-signingkey = xxxxx

set this in your ~/.gitconfig

use dash(-) to separate the different parts, for example: user.email -> user-email.

because .gitconfig can not use dash as the key.

make install

you can use make install to place the pre-commit file, and change the .gitconfig mannualy.

Thanks

Thanks to pgils/multi-email-git-hook, the project has helped me a lot.

References

About

DEPRECATED: use Git hook to set git user info based on directory name.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published