# Quick Git Cheat Sheet (git.cheatsheet.md)

Context:

- Two dev environments: macOS and Linux.
- One central bare repository on a Linux server:  
  `/home/intel145/websites/gitrepo/proj1.git`
- SSH access on port 2222.
- You use `main` + tags (`v1`, `v2`, …) for versions.

Remote URL (used below):

```text
ssh://intel145@209.182.212.74:2222/home/intel145/websites/gitrepo/proj1.git
```

Adjust paths/user/host/port as needed.

---

## Cheat Table

| Action | On macOS dev | On Linux dev | From repository (server) | Comments |
|--------|--------------|--------------|--------------------------|----------|
| **Create new dev project: proj1 (local only)** | `mkdir -p ~/projects/proj1 && cd ~/projects/proj1`<br>`git init`<br>`echo "# proj1" > README.md`<br>`git add .`<br>`git commit -m "Initial commit"` | Same commands, e.g.:<br>`mkdir -p ~/dev/proj1 && cd ~/dev/proj1`<br>`git init`<br>`echo "# proj1" > README.md`<br>`git add .`<br>`git commit -m "Initial commit"` | Not applicable (this is local‑only setup). | Do this when starting a brand‑new project before connecting to a remote. |
| **Create new central repository (bare) on server** | Not done on Mac; run on server:<br>`ssh -p 2222 intel145@209.182.212.74`<br>`mkdir -p ~/websites/gitrepo`<br>`cd ~/websites/gitrepo`<br>`git init --bare proj1.git` | Same as macOS: run on server via SSH. | `ssh -p 2222 intel145@209.182.212.74`<br>`mkdir -p ~/websites/gitrepo`<br>`cd ~/websites/gitrepo`<br>`git init --bare proj1.git` | Bare repo is the central “server” storage; never edit files inside it. |
| **Connect local dev repo to central repo** | From `~/projects/proj1`:<br>`git remote add origin ssh://intel145@209.182.212.74:2222/home/intel145/websites/gitrepo/proj1.git`<br>`git push -u origin main` | From `~/dev/proj1`:<br>`git remote add origin ssh://intel145@209.182.212.74:2222/home/intel145/websites/gitrepo/proj1.git`<br>`git push -u origin main` | Not applicable (this is done in working copies, not in bare repo). | Run once per working copy to link it to the central repo. |
| **Update proj files, create version 1, tag, update repository** | In `~/projects/proj1`:<br>`# edit files`<br>`git add -A`<br>`git commit -m "v1 work"`<br>`echo "1.0.0" > VERSION`<br>`git add VERSION`<br>`git commit -m "Bump version to 1.0.0"`<br>`git tag -a v1 -m "Release v1"`<br>`git push origin main`<br>`git push origin --tags` | Same in `~/dev/proj1`:<br>`# edit files`<br>`git add -A`<br>`git commit -m "v1 work"`<br>`echo "1.0.0" > VERSION`<br>`git add VERSION`<br>`git commit -m "Bump version to 1.0.0"`<br>`git tag -a v1 -m "Release v1"`<br>`git push origin main`<br>`git push origin --tags` | Not applicable (tags and commits are created in working copies, then pushed). | Use `git-bump-version 1.0.0` if you have the script instead of manual VERSION + tag commands. |
| **Get latest version of proj1 into dev/proj1fix folder** | `mkdir -p ~/dev`<br>`cd ~/dev`<br>`git clone ssh://intel145@209.182.212.74:2222/home/intel145/websites/gitrepo/proj1.git proj1fix` | `mkdir -p ~/dev`<br>`cd ~/dev`<br>`git clone ssh://intel145@209.182.212.74:2222/home/intel145/websites/gitrepo/proj1.git proj1fix` | Not applicable (cloning is done from a client, not inside the bare repo). | Creates a new working copy `proj1fix` with the latest `main`. |
| **Update files in proj1fix and send back to proj1 repository** | In `~/dev/proj1fix`:<br>`# edit files`<br>`git add -A`<br>`git commit -m "Fixes"`<br>`git push origin main` | Same in `~/dev/proj1fix` on Linux:<br>`# edit files`<br>`git add -A`<br>`git commit -m "Fixes"`<br>`git push origin main` | Not applicable (commits and pushes happen from working copies). | If you want a new version, also run `./git-bump-version 1.1.0` and push tags. |
| **Get list of files being edited / changed now** | In any working copy:<br>`git status` | Same:<br>`git status` | Not applicable (bare repo has no working tree, so `git status` isn’t meaningful there). | Shows modified, staged, and untracked files in that working copy. |
| **List all files in proj1 (current version)** | In `~/projects/proj1` or `~/dev/proj1fix`:<br>`git ls-files`<br>or<br>`git ls-tree -r HEAD --name-only` | Same commands in any proj1 working copy. | From server, in a working copy (e.g. `/home/intel145/websites/apps/proj1`):<br>`git ls-files` | Bare repo itself is not meant for browsing files; use a working copy or `git ls-tree` on refs. |
| **Compare README.md in proj1 v1 vs v2** | In any proj1 working copy:<br>`git diff v1 v2 -- README.md` | Same:<br>`git diff v1 v2 -- README.md` | From a server working copy:<br>`git diff v1 v2 -- README.md` | Shows line‑by‑line differences between the two tagged versions. |
| **Get v1 of file README.md (view or save)** | View:<br>`git show v1:README.md`<br>Save:<br>`git show v1:README.md > README.v1.md` | Same:<br>`git show v1:README.md`<br>`git show v1:README.md > README.v1.md` | From a server working copy:<br>`git show v1:README.md` | Does not change your current file; just prints or saves the old version. |
| **See history of README.md with versions (tags)** | `git log --decorate --oneline -- README.md` | Same. | Same in a server working copy. | Shows commits and any tags that include them for that file. |
| **Check what version (tag) current commit is at** | `git describe --tags --always`<br>`cat VERSION` | Same. | Same in a server working copy. | `git describe` tells nearest tag; `VERSION` is your project’s version file. |
| **Create a fix branch instead of changing main directly** | In any working copy:<br>`git checkout main`<br>`git pull`<br>`git checkout -b fix/readme`<br>`# edit, commit`<br>`git push -u origin fix/readme` | Same. | Not applicable (branches are created in working copies). | Use branches for features/fixes; merge to `main` later and tag a new release. |

---

## Additional Recommended Commands

These are useful across both macOS and Linux dev environments.

### See which files changed between two versions

```bash
git diff --name-only v1 v2
```

### See full change summary between versions

```bash
git diff --stat v1 v2
```

### Show content of any file at a given tag

```bash
git show v1:path/to/file
```

### Restore a file to its v1 state (in working tree)

```bash
git checkout v1 -- README.md
```

This stages the old version; commit if you want to keep it.

### List all tags (versions) in the project

```bash
git tag -l
```

### List branches (local and remote)

```bash
git branch -a
```

### Fast, no‑pager diff

```bash
git --no-pager diff v1 v2 -- README.md
```

Or configure:

```bash
git config --global core.pager "less -F -X"
```

### Quick “am I at a released version?” check

```bash
cat VERSION
git describe --tags --always
git status
```

- Clean tree + exact tag → you’re at a released version.
- Commits after tag → you’re working toward the next release.

---

Use this cheat sheet together with `tasks.md` and `faq1.md`–`faq4.md` for full context and examples.
