# Git Cheatsheet

## Topics

### General

* https://www.atlassian.com/git/tutorials/
* https://git-scm.com/doc

### Cases

Pulling all branches:

http://stackoverflow.com/questions/67699/clone-all-remote-branches-with-git

Initializing new repo from existing:

https://help.github.com/articles/adding-an-existing-project-to-github-using-the-command-line/

Git remote actions without re-entering creds:

http://stackoverflow.com/questions/8588768/git-push-username-password-how-to-avoid

Removing sensitive data from repo:

https://help.github.com/articles/removing-sensitive-data-from-a-repository/

Rewriting history:

https://robots.thoughtbot.com/git-interactive-rebase-squash-amend-rewriting-history

Git filter branch:

https://manishearth.github.io/blog/2017/03/05/understanding-git-filter-branch/

---

Set remote for existing repo.
```
$ git remote add origin https://github.com/user/repo.git
```

Fetch all branches from repo.
```
$ git fetch --all
```

---

### Plumbing Commands

```
git cat-file -p <hash>
```
Takes an git object hash and prints its contents. `-t` flag prints the hash type.
Works with hashes to give object information.

```
git hash-object <obj>
```
Takes an object and hashes it. `-w` flag writes object hash to .git/objects
Works with objects to provide hash related services.

```
git update-ref refs/<path> <hash>
```
Points `ref/<path>` to `<hash>`.

```
git verify-pack -v .git/objects/pack/<pack>
```
Validates and prints contents of git pack.

