1

introduction

2

My repository contains a bootstrap script that I use to setup the following folder structure:

3

4
home
5
├── .gitconfig
6
└── code
7
    ├── personal
8
    │   └── .gitconfig
9
    └── work
10
        └── .gitconfig
5

6

I organize my projects into two directories: ~/code/personal for personal projects and ~/code/work for

7

work-related ones. Additionally, I've created symbolic links for three git configurations: one for each of the

8

aforementioned project directories, and a more general one in my home directory.

9

10

The overarching git configuration contains universal aliases and settings applicable to any project. These include

11

setting my editor to nvim, enforcing fast-forward merges, pruning during fetch operations, using rebase on

12

pull, etc.

13

14

The git configuration in ~/code/personal updates the email to my personal address. since this directory also serves

15

as the repository for my open-source contributions, it incorporates settings to sign all commits using my gpg key.

16

17

The final git configuration, designated for my ~/code/work directory, switches the email to my work address and

18

incorporates a commit template for conventional commits.

19

20

I also maintain two distinct ssh keys: one for personal/open-source projects and another for work. Given that most

21

companies require me to use their laptops, it's crucial for me to rotate these keys with each new client. It's

22

important to not retain old keys linked to your Github account, especially after returning the hardware to its owner.

23

24

Below, I'll provide instructions on how you can achieve a similar setup.

25

26

setup

27

We'll start with the global git configuration that we keep in our home directory:

28

29
[user]
30
  editor = "nvim"
31
 
32
[alias]
33
  unstage = reset
34
 
35
...
36
 
37
 
38
[includeif "gitdir:~/code/personal/"]
39
  path = ~/code/personal/.gitconfig
40
 
41
[includeif "gitdir:~/code/work/"]
42
  path = ~/code/work/.gitconfig
30

31

The key components in this configuration are the two [includeif] statements at the bottom. with these, we instruct git

32

to incorporate our specific configurations depending on the repositories path on our file system.

33

34

Now, this is what my personal config looks like:

35

36
[user]
37
  email = victor@conner.dev
38
  name = victor conner
39
  signingkey = 15d...
40
 
41
[commit]
42
  gpgsign = true
43
 
44
[gpg]
45
  program = gpg
46
 
47
[url "git@github.com-personal"]
48
  insteadof = git@github.com
37

38

Again, I've placed the interesting bit at the end. Here we're overriding the url of the repository to be

39

git@github.com-personal instead of git@github.com. This alteration is going to enable the automatic selection

40

between our two ssh keys.

41

42

If you don't have two separate ssh keys already you can go ahead and generate them like this:

43

44
ssh-keygen -t rsa -b 4096 -f ~/.ssh/work
45
ssh-keygen -t rsa -b 4096 -f ~/.ssh/personal
45

46

We can now add the following lines to your ssh config:

47

48
host github.com-work
49
hostname github.com
50
addkeystoagent yes
51
user git
52
identityfile ~/.ssh/work
53
identitiesonly yes
54
 
55
host github.com-personal
56
hostname github.com
57
addkeystoagent yes
58
user git
59
identityfile ~/.ssh/personal
60
identitiesonly yes
49

50

The right key will automatically get picked based on the project path. I've left out the git config I use for work,

51

and trimmed the others to highlight the relevant parts for this post. If you're curious about the full configuration you

52

check out my repository on Github.

52

53

The end

54

I usually tweet something when I've finished writing a new post. You can find me on Twitter

55

by clicking 

normalintroduction.md
||109:21

Recently Edited

Recently Edited

File name

Tags

Time to read

Created at

context

  • go
  • context
8 minutes2024-02-28

circular-buffers

  • go
  • concurrency
  • data processing
5 minutes2024-02-04

go-directives

  • go
  • compiler
  • performance
4 minutes2023-10-21

async-tree-traversals

  • node
  • trees
  • graphs
  • typescript
19 minutes2023-09-10

All Files

All Files

  • go

    5 files

  • node

    2 files

  • typescript

    1 file

  • frontend

    1 file

  • workflow

    7 files