Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Cover image for Setting up project-level gitconfig
Nikkhiel Seath
Nikkhiel Seath

Posted on

     

Setting up project-level gitconfig

Last week, I completely shifted my system to Arch Linux and during this process, I lost some config(s), settings, etc.

git config was one of them. I used to have a separate config like username, email, ssh key to use based on which project I was working on.
For example, my work projects require a different set of credentials (username, email, ssh-key) than the credentials I use on my personal projects.

I have done this before too but, after a while, I just tend to forget how to do it. This time, I am writing it in a post so that I can refer to it when required.

Steps

  1. Go to the directory where you store the projects and create a.project.gitconfig with the desired credentials:
[user]    name = work-username    email = username@work-domain.com
Enter fullscreen modeExit fullscreen mode
  1. Edit the user level.gitconfig present under$HOME/.gitconfig to include the following condition:
[includeIf "gitdir:ABSOLUTE_PROJECT_DIRECTORY_PATH"]    path = "ABSOLUTE_PROJECT_DIRECTORY_PATH/.project.gitconfig"
Enter fullscreen modeExit fullscreen mode

Basically, we are tellinggit:

"If you find a.git directory nested under this path then, use these set of credentials."

Verify

Now, go to a project inside the work/project-root directory and verify that the correct credentials is being used:

git config--list |grep-P"user|email"
Enter fullscreen modeExit fullscreen mode

Note (or Gotcha)

Keep in mind that this config will only be used bygit if it finds.git directory at that path or a parent.git directory.
For example:

work/|- .work.gitconfig|- project-a/   |- .git/|- project-b/   |- .git/
Enter fullscreen modeExit fullscreen mode

Now, my.work.gitconfig will be used when I am insideproject-a orproject-b but, not insidework.

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

A Human | Software Engineer | Open Source and Linux Enthusiast | A Consistent Learner | A Voracious Reader
  • Location
    Remote
  • Education
    University Of Hard Knocks
  • Work
    Frontend Developer @ YouGov
  • Joined

More fromNikkhiel Seath

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp