git,

Git 101: config

Oct 28, 2022 · 2 mins read · Post a comment

Git configuration or just git config is where you update the configuration at project, user and at system level. Here are some nuggets though that might help you with the basics.

Prerequisites

  • Git

Solution

config levels

There are 3 config levels:

  • --local: project level.
  • --global: OS’s user level (the home directory).
  • --system: system level across the entire server / machine.

Therefore, example common config file locations:

  • /repos/devcoops/.git/config: project level
  • ~/.gitconfig: global (user) level
  • /etc/gitconfig: system level

Besides editing configs using your personal favorite editor, you could do the same with:

git config --local -e

username and password

Setting up username and email address (global level):

git config --global user.name "Dev Coops"
git config --global user.email "[email protected]"

Note: Omit the --global flag if you want to configure username and email per project. However, you could also replace it with --system or --local whatever your case might be. This applies to all git config command examples across this post.

Verify user.name and user.email by running:

git config --list

.gitconfig / .config file:

[user]
        name = Dev Coops
        email = [email protected]

text editor

Specify the text editor:

git config --global core.editor vim

.gitconfig / .config file:

[core]
        editor = vim

init branch

Configure the initial branch. Since master is replaced by main as a default branch, run the following command:

git config --global init.DefaultBranch main

.gitconfig / .config file:

[init]
        DefaultBranch = main

prune during fetch

Usually you might want to clean up outdated branches, so instead of running git fetch --prune everytime before pulling, you could just run the following command:

git config --global fetch.prune true

.gitconfig / .config file:

[fetch]
        prune = true

removing config settings

Remove config settings could be done using the --unset flag. For instance, to remove your username, run:

git config --unset user.name

To cleanup everything, use the --unset-all flag. For instance:

git config --unset-all

Conclusion

To find more neat Git commands and hacks, simply browse the Git category. Feel free to leave a comment below and if you find this tutorial useful, follow our official channel on Telegram.

git