Some more git stuff I forgot to do after reinstalling

A few days ago I posted this article about how I set up my machine after re-installing OS.

I forgot a few nice steps I do, and it was a pain to find out what I was missing, and all of them were related to git settings.

Global Gitignore

Don't you hate when you have to add the same lines to .gitignore files all the time? Those damned .DS_Store files Mac drops in every folder you zip and unzip.

Well, instead of doing a copy-paste in every .gitignore you can have a global one.

I usually dump mine in ~ and it looks like so

-> % cat ~/.gitignore 
.DS_Store
[Tt]humbs.db
.idea

Now to make it official:

-> % git config --global core.excludesfile ~/.gitignore

From now on no stinking DS_Store will make it to your VCS.

Nano instead of Vim as Editor

If you ever worked with a team, you know that sometimes you need also to pull from a branch, and by default (usually) git calls vim to edit stuff like commit messages, who wants that!? Yuck.

You can change it to nano and have a much nicer life.

-> % git config --global core.editor "nano"

of course, you can change it to code or whatever you want it to be, but I find a cli text editor is easier to use from cli.

Disable default pager

Again, If you ever worked with a team, you know that sometimes you need to switch branches. And if the team does not clean after themselves you will have LOADS of branches, git by default uses | less kind of to page the result.

I HATE IT.

I want to see them all.

Well this command got my back

 git config --global pager.branch false

Zip dat Git

Small bonus command, which is not a setting is if you want to share the content of a git repo without sharing also the gitignored files.

Imagine like me that you want to move a node script into your raspberry pi, without all the node_modules/ and other artifacts that would make the zip 90 Gb.

git archive -o `basename $PWD`.zip -9 HEAD

This command will generate a folder_name.zip file in the folder of the git repository, using the files presents until the last commit, and ignoring everything else that is not versioned. Amazing.

Fin

And that is all folks.

4
Subscribe to my newsletter

Read articles from Vincenzo Ciaccio directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Vincenzo Ciaccio
Vincenzo Ciaccio

I am a guy who lives on this planet. I eat food and drink liquids. I do stuff with computers. I live in the UK but I am Italian (from Sicily).