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

# Git Notes

```
Still to document
- PRs (https://www.git-scm.com/docs/git-request-pull)
- Conflict resolution
- Squashing
- Options during an interactive rebase
```

### Commands

* [Repos](/general-dev/git-notes/repos.md)
* [Committing changes](/general-dev/git-notes/committing-changes.md)
* [Branches](/general-dev/git-notes/branches.md)
* [Merging & Rebasing](/general-dev/git-notes/merging-and-rebasing.md)
* [PRs](/general-dev/git-notes/prs.md)

### Useful Resources

* Git learning game: [https://learngitbranching.js.org](https://learngitbranching.js.org/)
* Useful commands for fixing mistakes: <https://ohshitgit.com>

### Connecting to GitHub

* Logging in to GitHub on the command line: <https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token>
  * Use a personal access token instead of a password
  * <https://stackoverflow.com/questions/35942754/how-can-i-save-username-and-password-in-git>
  * View stored credentials (plain text)
    * `vim ~/.git-credentials`
* Using SSH Key
  * <https://docs.github.com/en/authentication/connecting-to-github-with-ssh/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent>

### Git Configuration Settings

* View/edit git configuration settings
  * If there's nothing there already this will create a new file

```bash
vim ~/.gitconfig
```

* Add this to the `[alias]` section
  * Pretty view of commit tree for current branch

{% code overflow="wrap" fullWidth="false" %}

```bash
[alias] tree = log --color --graph --pretty=format:'%Cred%h%Creset -%C(bold magenta)%d%Creset %s %C(cyan)(%cr)%C(bold blue) <%an> %Creset' --date=relative --abbrev-commit --all

[alias] tree-current = log --color --graph --pretty=format:'%Cred%h%Creset -%C(bold magenta)%d%Creset %s %C(cyan)(%cr)%C(bold blue) <%an> %Creset' --date=relative --abbrev-commit --all
```

{% endcode %}

* Then run the commands

```bash
git tree
git tree-current
```

### Git Temp Patch

* A great way to get all the changes from a branch and see them on another branch

1\. Make sure you're on your feature branch

`git checkout your-branch`

2\. Create a patch of all changes since main (as a diff)

`git diff main > temp.patch`

3\. Checkout main and pull latest

`git checkout main git pull origin main`

4\. Apply the patch (this makes the changes uncommitted on main)

`git apply temp.patch`
