Git Tips

Use multiple git accounts

  • You might have a git for work and a personnal git.

  • If you need to use multiple git account the best way is to set multiple local configs and one global

  • In your home config file /home/username/.gitconfig

    defaultBranch = main

[includeIf "gitdir:/home/username/localfolderOne/"]
    path = /home/username/localfolderOne/.gitconfig

[includeIf "gitdir:/home/username/localfolderTwo/"]
    path = /home/username/localfolderTwo/.gitconfig
    directory = /docs
  • In you first local folder create another .gitconfig as follow

    name = First Last
    email =
    signingkey = ID-OF-GPG-KEY
    program = gpg
    gpgsign = true
    defaultBranch = main
  • In your second local folder do the same thing

  • If you need more info on how to create and setup gpg key check out this article on jigarius

  • To add a gpg key in github go to Settings>SSH and GPG key and click on "New GPG Key" and add the public key

  • After this setup when you will commit and push things you should be good to go.

Resolve user conflicts when pushing

Temporary solution

If you get an error like this when trying to push remote: Permission to repo.git denied to old_username A temporary solution is to push over https by specifying the username in the link like this: git push

More permanent solution

Make a grep about the user mentioned by the error message grep -iar old_username It takes a while but should give you the config file where the user is mentionned. mine was .config/gh/hosts.yml

Last updated