Skip to content

Commit

Permalink
post: publish gitconfig (#191)
Browse files Browse the repository at this point in the history
  • Loading branch information
maxpou authored Jun 11, 2024
1 parent 8923d1f commit d572eb9
Show file tree
Hide file tree
Showing 4 changed files with 169 additions and 0 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
169 changes: 169 additions & 0 deletions src/content/blog/2024/2024-06-11-gitconfig/index.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
---
title: A Look Inside My Personalized .gitconfig
description: Boost your Git efficiency! A simple config for a smoother workflow.
slug: gitconfig
date: 2024-06-11
language: en
cover: ./cover.jpg
tags: ['Git']
---

## Overview - How do I use git?

I use the CLI for almost everything except when I want to exclude files from the git add.

I never use the merge command, I always rebase. I prefer to have a cleaner history.

When I open a pull request I always have one unique commit. I update commits with --amend --no-edit
and force push.

Before I start with my config detail, you can see your config with
`git config --list --show-origin --show-scope` (it will also tell you the file location and the
scope).

## Separate work from side projects

```bash
[user]
email = [email protected]
name = Maxence Poutord

# overrides for a specific folder
[includeIf "gitdir:~/code/company/"]
path = ~/.gitconfig-work

[includeIf "gitdir:~/code/company/"]
email = [email protected]
```

Having `includeIf` allows you to better separate configs between your company project and your side
projects. You can override with an entire gitconfig file or you can also override a property.

## Sort branch&tags

```bash
[branch]
sort = -committerdate

[tags]
sort = -version:refname
```

When you `git branch -a`, everything is alphabetically sorted. With this, they will be ordered by
the last commit date.

When you have gazillions of tags, it’s sometimes better to sort them the other way around. So you
see the latest tags first.

## Auto-cleanup

```bash
[fetch]
prune = true
```

All `git fetch` will now clean branches that no longer exist on the remote repository.

Note: if you want to do a deep clean you can also run this
`git branch --no-merged | egrep -v "(^\*|main)" | xargs git branch -D` .

## Autocorrect mistyped command

```bash
[help]
autocorrect = 1
```

This corrects you when you have a typo in your command. If you type `git comit`, git will assume
that you meant ”commit” and run the command 0,1 second after.

## Default branch

```bash
[init]
defaultBranch = main
```

Set the default branch name to `main` (instead of `master`) for all newly created repositories.

## Editor

```bash
[core]
editor = vim
```

Change the editor (i.e. for commands like `git commit --amend` and `git rebase`).

πŸ’‘**Tips:** To use VSCode instead of Vim, replace it with `code --wait`

## Push

```bash
[push]
autoSetupRemote = true
```

Git automatically sets up a remote tracking branch when you push a new local branch for the first
time.

You will also get rid of messages like _"fatal: The current branch demo has no upstream branch"_.

## Colors

```bash
[color]
ui = auto
branch = auto
diff = auto
status = auto

[color "status"]
added = green
changed = yellow
untracked = red

[color "branch"]
current = yellow reverse
local = yellow
remote = green

[color "diff"]
meta = yellow bold
frag = magenta bold
old = red
new = green
```

This is a bit personal but here are the colors I use.

## Bonus - git log on steroids

I use bash aliases instead of git aliases.

```bash
alias glols='git log --graph --pretty='\''%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset'\'' --stat'
alias glol='git log --graph --pretty='\''%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset'\'
# β”‚ β”‚ β”‚ β”‚ └─ committer name
# β”‚ β”‚ β”‚ └─ date (relative)
# β”‚ β”‚ └─ message
# β”‚ └─ decorations (branch, heads or tags)
# └─ hash (abbreviated)
```

The first one will render this:

![Screenshot 2024-05-24 at 15.44.20.png](./glol.jpg)

The second is the same but with the file list:

![Screenshot 2024-05-24 at 15.44.20.png](./glols.jpg)

## Conclusion

My gitconfig is in my dotfiles https://github.com/maxpou/dotfiles/blob/main/gitconfig.

When I was writing this post, I discovered about
[git rerere](https://git-scm.com/book/en/v2/Git-Tools-Rerere) which seems to be interesting for
resolving conflicts. But, I’m not confident enough with it to put it here. So I may edit this post
later to add it :)

0 comments on commit d572eb9

Please sign in to comment.