47

I was wondering how am I going to change the contents of the command git config --list? I am going to pull/fork a repository from GitHub. I am going to configure such repositories on both of my Windows, Linux and Mac workstations.

codeforester
  • 39,467
  • 16
  • 112
  • 140
David B
  • 3,269
  • 12
  • 48
  • 80
  • Are you trying to set up different configurations for different repos ***on the same machine***, or did you only want to have different Git ***user settings*** on your different machines? If you just wanted different user settings, all you had to do was run `git config --global =`. –  Aug 12 '13 at 09:08
  • I would like to have different configuration for different repositories. But the question is that upon `git clone`, does GitHub know that I have cloned that selected repository or should I change the git configuration after cloning and before pulling? – David B Aug 12 '13 at 09:16
  • If all you wanted to do was change your `user.name` and `user.email` settings, then those won't matter until you start making commits in your local repo, and then push them to GitHub. They won't affect commits that you're pulling. –  Aug 12 '13 at 09:20

1 Answers1

97

If you want to set up configurations that are specific for a particular repository, you have two options, to configure it from the command line, or edit the repo's config file in an editor.

Option 1: Configure via command line

Simply use the command line, cd into the root of your Git repo, and run git config, without the --system and the --global flags, which are for configuring your machine and user Git settings, respectively:

cd <your-repo>
git config <setting-name> <setting-value>
git config <setting-name>=<setting-value> # alternate syntax

Option 2: Edit config file directly

Your other option is to edit the repo config file directly. With a default Git clone, it's usually the .git/config file in your repo's root folder. Just open that file in an editor and starting adding your settings, or invoke an editor for it at the command line using git config --edit.

Resources

You can learn more about configuring Git at the official Linux Kernel Git documentation for git config. In particular, you may be interested in seeing an example Git config:

# Core variables
[core]
        ; Don't trust file modes
        filemode = false
# Our diff algorithm
[diff]
        external = /usr/local/bin/diff-wrapper
        renames = true
[branch "devel"]
        remote = origin
        merge = refs/heads/devel
# Proxy settings
[core]
        gitProxy="ssh" for "kernel.org"
        gitProxy=default-proxy ; for the rest
[include]
        path = /path/to/foo.inc ; include by absolute path
        path = foo ; expand "foo" relative to the current file
        path = ~/foo ; expand "foo" in your $HOME directory

Edit

Addressing the original poster's question about how to change user.name and user.email per repository, here is how to do it via the command line. Switch to each repository, and run the following:

git config user.name "<name>"
git config user.email "<email>"

Since you're not using the --system or the --global flags, the above commands will apply to whichever repo you have in your terminal working directory only.

Community
  • 1
  • 1
  • Can you provide a tutorial? – David B Aug 12 '13 at 07:27
  • Have you read the information in the [git config manual](https://www.kernel.org/pub/software/scm/git/docs/git-config.html)? It should contain everything you need to know. If you're stuck on something in particular, edit your question to let people know what you're stuck on. –  Aug 12 '13 at 07:34
  • I have ignored the manual and I have only a few known commands about git. I am still confused on how this can be done? Can you provide a step-by-step tutorial on how to set a different git config for a different repository? – David B Aug 12 '13 at 07:49
  • 3
    I'm not sure what else there is to say, I've already given everything you need to configure a repo-specific Git config file, just edit the `.git/config` file in the directory of each Git repo. Did you try that? Did you have problems with anything specifically? ***Did you need help with any specific configuration settings***? Did you want advice on which settings should be ***different*** between your Windows, Mac, and Linux machines? –  Aug 12 '13 at 08:08
  • I was wondering before cloning a particular repository from [GitHub](https://github.com/) will indicate in the pull list my private account. I wanted to switch to my public account prior to cloning of the repository. – David B Aug 12 '13 at 08:14
  • @Dr.Java I'm sorry, but this is still not at all clear. What is this "pull list" that you're talking about? And what do you mean by private vs public account? GitHub accounts shouldn't have anything to do with repo-specfic configurations, other than maybe affecting the urls you use for remote repos, and maybe the email address you use for commits in the repo. –  Aug 12 '13 at 08:24
  • I would like to change the value of the property `user.name` and `user.email` for different repository. – David B Aug 12 '13 at 08:33
  • @Dr.Java updated answer, does that address all of your configuration issues? –  Aug 12 '13 at 08:38
  • I've tried to create a directory then I've tried to do the commands above it returns to me this error: `error: could not lock config file .git/config: No such file or directory`. I've I clone a particular project would there be a record that I've clone it? – David B Aug 12 '13 at 08:42
  • @Dr.Java you can get the error that you mentioned if you tried to use `git config` in a directory that hasn't actually been initialized or cloned as a Git directory. How did you try to clone your repo? Did you use `git clone`, or are you using a Git GUI? Also, ***did you `cd` into the cloned repo before you tried running the `git config` commands***? –  Aug 12 '13 at 08:46
  • I am using `git clone`. – David B Aug 12 '13 at 08:48
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/35254/discussion-between-cupcake-and-dr-java) –  Aug 12 '13 at 08:48
  • Go to the directory having your `.git` folder. Run `git config user.name ` and `git config user.email ` and bam! – waqasgard Nov 26 '18 at 13:10
  • I'm just making an init script to install my gitconfig alias locally into the repo's `.git/config` same thing people often do with hooks – Ray Foss Nov 04 '20 at 23:00