> For the complete documentation index, see [llms.txt](https://notes.halcyon.hr/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://notes.halcyon.hr/terminal-extravaganza/git.md).

# git

git is everyone's favorite version control system.

## How does it work?

* Git How To: <https://githowto.com> - learn the basics
* The official Git Book: <https://git-scm.com/book/en/v2> - everything you ever wanted to know about Git
* Learn Git Branching: <https://learngitbranching.js.org> - test your knowledge without having to set up intricate and contrived repositories
* Intermediate to advanced tutorial of git and its internals: <http://think-like-a-git.net> - learn how does it actually work&#x20;
* Oh shit, git: <http://ohshitgit.com> - "Mom come pick me up I'm scared"

## Global .gitignore

There is nothing that annoys me more than cloning a bunch of `.vscode`, `.atom`, `.idea` and other directories alongside an interesting project. To keep your personal preferences from infiltrating everyone else's systems, you should use a global `.gitignore` file, which I like to place in my `$HOME` as `.gitignore_global` (but if you have a Linux system you should probably put it in your `~/.config` directory).

Run the following command to introduce `~/.gitignore_global` to Git:

`git config --global core.excludesfile ~/.gitignore_global`

&#x20;Then you can use the familiar .gitignore syntax to ignore commonly ignored files:

```
.vscode
tags*
.DS_Store
```

## Public and private configuration

If you share your dotfiles on the World Wide Web, or you just keep them in a git repo as a backup, you should probably not include your name, email and other things in your main git config, just so that others who might want to use it don't accidentally commit as you. Thankfully, Git lets us include configs into one another using the `include` directive:

{% code title=".gitconfig" %}

```
[include]
    path = ~/.gitconfig.local
```

{% endcode %}

Now you can add `.gitconfig.local` to your `.gitignore` in your dotfiles repository and publish the rest of the thing, while adding private config to the local one:

{% code title=".gitconfig.local" %}

```
[user]
	name = Ivan Oštrić
	email = ivan@halcyon.hr
	signingkey = 314838F5043A5EFF
```

{% endcode %}
