Skip to content

Git Config

Posted on:August 6, 2023

Quick Git set-up

This is a guide for future me to reference. Every now and then I like to switch to a new Linux distro, just wipe everything and start fresh. This means I have to configure all the things again, which isn’t so bad. So this is a guide to how I like to have Git set up and maybe if it helps somebody else, then that’s a win win.

So obviously, the first two are:

git config --global user.name "Boogie Brown"

if your name is Boogie Brown then that’s how you’d do that, and then your email:

git config --global user.email "email@address.here"

Then there’s the ever important:

git config --global init.defaultBranch main

because reasons.

And then we need color in our lives so we can do:

git config --global color.ui auto

This next one is for which editor to open for commits and stuff, I like micro:

git config --global core.editor micro

This next one is up for debate. Some say to set pull.rebase to false. But if you’re working with other people on a project, then true makes for a cleaner history, although possibly more complex with regard to resolving conflicts. See here: https://spin.atomicobject.com/2020/05/05/git-configurations-default/

git config --global pull.rebase true 

Then again, if you prefer a simpler workflow and don’t mind having a new merge commit in your history every time you pull, then do:

git config --global pull.rebase false

which I think is the default setting anyway. I opted for true.

If you want to authenticate with GitHub via SSH, then this is how you do it, first check for existing key:

ls ~/.ssh/id_ed25519.pub

“No such file or directory” is my output, so there isn’t one there yet. Therefore, we run this command to generate our key pair:

ssh-keygen -t ed25519 -C email@address.here

By the way, I’m referring to: https://www.theodinproject.com/lessons/foundations-setting-up-git for a lot of this information so far. That last command will generate an SSH key pair in your specified directory, or default directory (~/.ssh) if you just press enter without typing anything, which is what I did, just press enter for all three questions, and thanks to explainshell I can tell you that the -t is for specifying type and the -C is for specifying comment which is for the email address.

The next step is telling GitHub about our new SSH public key (the one ending in .pub, not the other one, that one’s secret). Go to your GitHub account settings, then on the left click on “SSH and GPG keys”, then click the blue button that says “New SSH key”. Give it a name, I usually just put in my OS and the current date for a name, then go back to your terminal and cat the key file, first list it so you can see the name:

ls .ssh

or if you prefer exa like me:

exa .ssh

then get the contents (I actually prefer bat over cat except in this case as the output from cat is easier to copy):

cat .ssh/id_ed25519.pub

Select all of that bad boy, copy it, take it over to GitHub and paste it into the text area labelled “key” and press the “Add SSH key” button.

Now click “New SSH key” again, change the “Key type” field from “Authentication Key” to “Signing Key” and do it again. Add the same key a second time as a signing key instead of an authentication key.

The first time you connect to GitHub via SSH, (git clone or git pull) GitHub will ask you to verify that you want to continue, this will create a known_hosts file and set you up so you’re good from then on.

Now, to tell Git about the signing key, one more thing first:

eval "$(ssh-agent -s)"

to make sure our lovely ssh-agent is ready for us, if you get a PID then you’re set:

ssh-add ~/.ssh/id_ed25519

and you should see something like, “Identity added: /home/you/.ssh/id_ed25519”. Now let’s tell Git about our new key, first:

git config --global commit.gpgsign true
git config --global gpg.format ssh
git config --global user.signingKey /home/you/.ssh/id_ed25519.pub

This last one you want to enter your public key. And now you will get that pretty blue verified badge on GitHub. See here: https://docs.github.com/en/authentication/managing-commit-signature-verification/telling-git-about-your-signing-key

And finally, I like to use Meld as my diff tool and merge tool because it’s pretty neat, your mileage may vary.

We’re gonna do this via editing our .gitconfig file which I think offers finer-grained control over things like in which pane to place which file in the Meld UI.

Install Meld if you don’t already have it, then add the following to your .gitconfig file in your home directory:

[diff]
    tool = meld
[difftool "meld"]
    path = /usr/bin/meld
    cmd = meld "$LOCAL" "$REMOTE"
[difftool]
    prompt = false

And then you can do the same thing for a merge tool if you want to use Meld as your tool in which to resolve merge conflicts. I like using Meld so I’m going to configure that too:

[merge]
    tool = meld
[mergetool "meld"]
    path = /usr/bin/meld
    cmd = meld "$LOCAL" "$MERGED" "$REMOTE" --output "$MERGED" 
[mergetool]
    prompt = false

I’m not going to go into a whole lot of depth about that last line there. Basically, it’s saying the file to be edited will be in the middle pane, and that Meld should save that file for its output.

See: this answer on StackOverflow for more about that.

And there you have it! My Git config. I hope this can help somebody else if not just future me.