---
# System prepended metadata

title: Git cheatsheet

---

# Git cheatsheet

### Global git config

Set up user details in git
```
git config --global user.name "{Full Name}"
git config --global user.email "user@example.com"
```

Tell git to do a rebase on pull
``` 
git config --global pull.rebase true
```

### Setting up remotes
```
git clone https://github.com/username/my-fork
cd my-fork
git remote add upstream https://github.com/org/original-repo
```

### Doing a rebase
Figure out how many commit you have to rebase.
```
git log --oneline --graph upstream/main...HEAD
```

Then start the interactive rebase:

```
git rebase -i HEAD~<n> # where n is the count from the log command
```

Git will pull up an editor, with the commits listed. If you want to abort the command, just empty out the file, and save and close. This will stop the rebase.

Otherwise, you can change the first column to have different commands, like squash(s), edit(e). You can use the single letter version, or spell it out.



### Add Signed-off-by to your commit message

```
git commit -s
```
or on an existing commit
```
git commit --amend -s
```

### Add some useful aliases for git

https://github.com/ConradIrwin/git-aliae

### Pretty diffs

https://github.com/so-fancy/diff-so-fancy

```
brew install diff-so-fancy
git config --global core.pager "diff-so-fancy | less --tabs=4 -RFX"
git config --global interactive.diffFilter "diff-so-fancy --patch"
```

If you're running Fedora/RHEL:

https://copr.fedorainfracloud.org/coprs/apuimedo/diff-so-fancy/

### Github UI cli binary
https://cli.github.com
https://cli.github.com/manual

With Homebrew:
```
brew install gh
```

### Initial repo setup

Fork the upstream repo ![Github UI Fork](https://i.imgur.com/rvaEn7U.png)

Or use the CLI
```
gh repo fork --clone --org your_user --remote --remote-name upstream originalorg/forked_repo
```

This does the same as these steps:

```
git clone https://github.com/myuser/forked_repo
cd forked_repo
git remote add upstream https://github.com/originalorg/forked_repo
git branch --set-upstream-to upstream/main
```

### Linking a PR with an Issue

https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue
