daemon-sec-cheatsheet

The cheatsheet vault for operators: AD, enumeration, exploitation, priv-esc, web, DFIR
git clone https://git.daemon-sec.xyz/daemon-sec-cheatsheet.git
Log | Files | Refs | README | LICENSE

git-complete-branch-vault-management-guide.md (26855B)


      1 ---
      2 title: "Git — Complete Branch & Vault Management Guide"
      3 description: "git init git remote add origin https://github.com/yourusername/your-repo.git"
      4 category: git-workflow
      5 tags: ["git-workflow", "adcs"]
      6 tools: []
      7 difficulty: intermediate
      8 updated: "2026-08-10"
      9 source: "vault:Git — Complete Branch & Vault Management Guide.md"
     10 ---
     11 # Initialise the repo if you haven't already
     12 git init
     13 git remote add origin https://github.com/yourusername/your-repo.git
     14 
     15 # Add all your main vault files
     16 git add .
     17 git commit -m "Initial main vault setup"
     18 git push -u origin main
     19 ```
     20 
     21 > [!info]+ Command Breakdown
     22 > 1. **`git init`**: Initialises a new local [Git](https://git-scm.com/docs/git-init) repository in the current directory
     23 > 2. **`git remote add origin <url>`**: Links your local repo to the remote GitHub repository
     24 > 3. **`git add .`**: Stages all files in the current directory for commit
     25 > 4. **`git commit -m "..."`**: Commits staged files with a descriptive message
     26 > 5. **`git push -u origin main`**: Pushes to GitHub and sets `origin/main` as the upstream tracking branch — `-u` only needed on the first push
     27 
     28 ---
     29 
     30 **Step 2 — Create a completely empty new vault branch**
     31 
     32 ```bash
     33 # Create orphan branch — NO history, NO files carried over from main
     34 git checkout --orphan HTB-Labs
     35 
     36 # Wipe every file that carried over
     37 git rm -rf .
     38 ```
     39 
     40 > [!info]+ Command Breakdown
     41 > 1. **`git checkout --orphan HTB-Labs`**: Creates a new branch with zero commit history — files from the current branch are present in the working tree but untracked, so the next step wipes them
     42 > 2. **`git rm -rf .`**: Recursively force-removes all files from the working tree and staging area, leaving a completely blank slate
     43 > 3. *`main` is entirely untouched by this operation*
     44 
     45 > [!success]+ Expected Result
     46 > Completely blank slate on `HTB-Labs`. The `main` branch and all its files remain untouched.
     47 
     48 ---
     49 
     50 **Step 3 — Add vault files and push**
     51 
     52 ```bash
     53 # Create your new vault structure
     54 mkdir HTB-Labs
     55 echo "# HTB Labs Vault" > README.md
     56 
     57 # Add, commit, and push
     58 git add .
     59 git commit -m "Initial HTB Labs vault setup"
     60 git push -u origin HTB-Labs
     61 ```
     62 
     63 > [!info]+ Command Breakdown
     64 > 1. **`mkdir HTB-Labs`**: Creates a new directory for the vault structure
     65 > 2. **`echo "# HTB Labs Vault" > README.md`**: Creates a minimal README — required for an initial commit on an empty branch
     66 > 3. **`git push -u origin HTB-Labs`**: Pushes the orphan branch to GitHub and sets upstream tracking
     67 
     68 > [!important]+ Adding More Vaults Later
     69 > Repeat Steps 2 and 3 for every new vault — always start from `--orphan`. Never use `git checkout -b` to create a new vault branch or you will inherit files from the current branch.
     70 
     71 ---
     72 
     73 ## Section 3 — Workflow B — Move Existing Edits to a New Branch
     74 
     75 > [!faq]+ Which Scenario Are You In?
     76 > Before running anything, check your current state:
     77 > ```bash
     78 > git status
     79 > ```
     80 > 1. Shows **modified files** → edits are **uncommitted** — follow Scenario A below
     81 > 2. Shows **nothing to commit** → edits are already **committed** on main — follow Scenario B below
     82 
     83 ---
     84 
     85 **Scenario A — Edits are uncommitted (not yet committed)**
     86 
     87 *Your changes exist only as working-directory edits*
     88 
     89 ```bash
     90 # 1. Create a new branch and switch to it — uncommitted edits travel with you automatically
     91 git checkout -b my-new-branch
     92 
     93 # 2. Commit your edits on the new branch
     94 git add .
     95 git commit -m "Site edits — moved to own branch"
     96 
     97 # 3. Push the new branch to GitHub
     98 git push -u origin my-new-branch
     99 ```
    100 
    101 > [!info]+ Command Breakdown
    102 > 1. **`git checkout -b my-new-branch`**: Creates the new branch and switches to it — all uncommitted file changes come with you because they live in the working directory, not on any branch
    103 > 2. **`git add .`**: Stages every modified file
    104 > 3. **`git commit -m "..."`**: Locks your edits into the new branch's history
    105 > 4. **`git push -u origin my-new-branch`**: Creates the branch on GitHub and sets upstream — Railway or any other service can now be pointed at this branch
    106 
    107 > [!success]+ Expected Result
    108 > 1. `my-new-branch` exists on GitHub with all edits committed
    109 > 2. `main` is unchanged — still matches the original repo
    110 > 3. No merging has occurred — the two branches are fully independent
    111 
    112 ---
    113 
    114 **Scenario B — Edits are already committed on main**
    115 
    116 *You already ran `git commit` — the changes are in `main`'s history*
    117 
    118 ```bash
    119 # 1. Create a new branch at the current point in history
    120 #    This copies main's current state (including your commits) into the new branch
    121 git checkout -b my-new-branch
    122 
    123 # 2. Push the new branch to GitHub — DO THIS BEFORE TOUCHING MAIN
    124 git push -u origin my-new-branch
    125 
    126 # 3. Switch back to main
    127 git checkout main
    128 
    129 # 4. Reset main back to match the original remote
    130 git reset --hard origin/main
    131 ```
    132 
    133 > [!info]+ Command Breakdown
    134 > 1. **`git checkout -b my-new-branch`**: Creates a new branch starting from exactly where `main` currently is — all committed edits are included
    135 > 2. **`git push -u origin my-new-branch`**: Pushes the new branch to GitHub **before** touching `main` — your work is safely backed up remotely
    136 > 3. **`git checkout main`**: Switches back to main to clean it up
    137 > 4. **`git reset --hard origin/main`**: Forces local `main` to exactly match the GitHub remote — effectively removes your local commits from it
    138 
    139 > [!warning]+ Push the New Branch BEFORE Resetting Main
    140 > Push `my-new-branch` to GitHub first. Once you reset `main`, those commits are gone from `main` locally. They are safe on `my-new-branch` — but only if you pushed it first.
    141 
    142 > [!success]+ Expected Result
    143 > 1. `my-new-branch` on GitHub contains all your edits
    144 > 2. `main` is clean — matches the original forked repo
    145 > 3. No merging has occurred
    146 
    147 ---
    148 
    149 ## Section 4 — Switching Between Vaults / Branches
    150 
    151 ```bash
    152 git checkout main        # Switch to Personal Vault
    153 git checkout HTB-Labs    # Switch to HTB Vault
    154 git checkout Work-Notes  # Switch to Work Vault
    155 git checkout -           # Jump back to the previous branch instantly
    156 ```
    157 
    158 > [!info]+ Command Breakdown
    159 > 1. **`git checkout <branch>`**: Switches the working directory to the specified branch — because each vault branch was created with `--orphan`, switching branches is equivalent to switching between entirely different vaults
    160 > 2. **`git checkout -`**: Shorthand for the previously checked-out branch; equivalent to `cd -` in shell
    161 
    162 > [!warning]+ Obsidian Users — Branch Switching Warning
    163 > Always close the current vault in Obsidian **before** running `git checkout`. Obsidian can recreate files or get confused when files suddenly change under it. After switching, reopen Obsidian and point it to the same folder.
    164 
    165 > [!warning]+ Uncommitted Changes Block Switching
    166 > 1. If local changes conflict with the target branch, switching will abort
    167 > 2. Resolve by committing: `git add . && git commit -m "WIP"`
    168 > 3. Or stash: `git stash` — then restore after switching: `git stash pop`
    169 
    170 ---
    171 
    172 ## Section 5 — Saving Changes (Daily Workflow)
    173 
    174 > [!important]+ Always Verify Your Branch Before Committing
    175 > Running a commit on the wrong branch is the most common mistake in a multi-vault setup. Always check first.
    176 
    177 ```bash
    178 # Check which branch/vault you are on
    179 git branch
    180 
    181 # Save changes to whichever vault you're currently on
    182 git add .
    183 git commit -m "Update HTB writeup for box XYZ"
    184 git push
    185 ```
    186 
    187 > [!info]+ Command Breakdown
    188 > 1. **`git branch`**: Lists all local branches — asterisk (`*`) marks the currently active one
    189 > 2. **`git add .`**: Stages all new, modified, and deleted files in the working directory
    190 > 3. **`git commit -m "..."`**: Creates a snapshot of staged changes — use descriptive messages for easy history navigation
    191 > 4. **`git push`**: Pushes committed changes to the tracked remote branch on GitHub
    192 
    193 **Standard vault update pattern — switch, change, commit, push**
    194 
    195 ```bash
    196 git checkout HTB-Labs
    197 git add .
    198 git commit -m "Add new lab notes"
    199 git push
    200 ```
    201 
    202 > [!tip]+ Golden Rules for Multi-Vault Repos
    203 > 1. Always run `git branch` before committing — confirm you are on the right vault
    204 > 2. Use `--orphan` for new vaults — never branch off main or you will inherit its files
    205 > 3. Close Obsidian before switching branches to avoid file conflicts
    206 > 4. Push regularly — GitHub is your backup for every vault
    207 
    208 ---
    209 
    210 ## Section 6 — Pointing Railway at a Branch
    211 
    212 > [!tip]+ Railway Deployment Branch
    213 > 1. Go to your project in [Railway](https://railway.app/)
    214 > 2. Navigate to **Settings → Source**
    215 > 3. Change the deployment branch from `main` to your edits branch
    216 > 4. Railway will now build and deploy from that branch
    217 > 5. `main` remains your clean baseline / fallback
    218 
    219 ---
    220 
    221 ## Section 7 — Inspecting History with git log
    222 
    223 > [!info]+ [git log](https://git-scm.com/book/en/v2/Git-Basics-Viewing-the-Commit-History) Overview
    224 > Inspects commit history and surfaces commit references — hashes, HEAD pointers, tags, branches
    225 > 1. Displays commits in reverse chronological order by default
    226 > 2. Opens in a pager — press `q` to exit, arrow keys to scroll
    227 > 3. Supports filtering by author, file, date, and branch
    228 > 4. Read-only — makes no changes to the repo or working tree
    229 
    230 **Commit Reference Types**
    231 
    232 | Reference | Example | Meaning |
    233 |---|---|---|
    234 | Full SHA-1 | `346ca091076783c70623aba03fb7139d3d27134f` | Exact commit identifier |
    235 | Short SHA | `346ca09` | First 7 chars — minimum Git requires |
    236 | Tag | `v1.0` | Human-readable bookmark |
    237 | Branch name | `main`, `HTB-Labs` | Latest commit on that branch |
    238 | HEAD | `HEAD` | Currently checked-out commit |
    239 | Relative | `HEAD~2`, `HEAD^` | Commits before HEAD |
    240 
    241 **`git log` — Flags**
    242 
    243 | Flag | Effect |
    244 |---|---|
    245 | `--oneline` | Shortened hash + message, one line per commit |
    246 | `--graph` | ASCII branch/merge graph alongside log |
    247 | `--all` | Show commits from all branches |
    248 | `--decorate` | Show branch/tag names next to commits |
    249 | `-n <number>` | Limit to `n` most recent commits |
    250 | `--author="Name"` | Filter by author |
    251 | `-- <file>` | Show only commits touching a specific file |
    252 
    253 ```bash
    254 # Best daily driver — compact, decorated, graphed, all branches
    255 git log --oneline --graph --decorate --all
    256 
    257 # Last 5 commits, compact
    258 git log --oneline -5
    259 
    260 # Commits touching a specific file
    261 git log --oneline -- hello.html
    262 ```
    263 
    264 > [!info]+ Command Breakdown
    265 > 1. **`--oneline --graph --decorate --all`**: Combines short hash, ASCII branch topology, branch/tag names, and all branches into the clearest possible history view
    266 > 2. **`-5`**: Limits output to the 5 most recent commits — replace with any integer
    267 > 3. **`-- hello.html`**: The `--` separator tells Git what follows is a file path, not a branch name — filters log to only commits that modified that file
    268 
    269 ---
    270 
    271 ## Section 8 — Tagging Versions
    272 
    273 > [!info]+ [git tag](https://git-scm.com/book/en/v2/Git-Basics-Tagging) Overview
    274 > Creates permanent, human-readable bookmarks on specific commits (e.g. release versions)
    275 > 1. Two types: **lightweight** (pointer only) and **annotated** (full metadata object)
    276 > 2. Tags are local until explicitly pushed to a remote
    277 > 3. Annotated tags are required for `git describe` to work correctly
    278 > 4. Tags can be applied retroactively to any past commit using its hash
    279 
    280 **Tag Types**
    281 
    282 | Type | Command | Use Case |
    283 |---|---|---|
    284 | Lightweight | `git tag v1.0` | Quick private/temporary label; no metadata |
    285 | Annotated | `git tag -a v1.0 -m "Release"` | Public releases; includes author, date, message |
    286 
    287 **`git tag` — Flags**
    288 
    289 | Flag | Effect |
    290 |---|---|
    291 | `-a` | Create an annotated tag (stores author, date, message) |
    292 | `-m "<msg>"` | Attach a message inline (skips editor prompt) |
    293 | `<tagname> <hash>` | Tag a past commit by hash |
    294 | `-d <tagname>` | Delete a tag locally |
    295 | `-l "v1.*"` | List tags matching a pattern |
    296 
    297 ```bash
    298 # Annotated tag on current HEAD
    299 git tag -a v1.0 -m "First public release"
    300 
    301 # Tag a specific past commit
    302 git tag -a v0.9 558151a -m "Pre-release"
    303 
    304 # List all tags
    305 git tag
    306 
    307 # Delete a local tag
    308 git tag -d v1.0
    309 ```
    310 
    311 > [!info]+ Command Breakdown
    312 > 1. **`-a v1.0 -m "..."`**: Creates a full annotated tag object — `-m` attaches the message inline, bypassing the editor
    313 > 2. **`558151a`**: Short SHA of a past commit — retrieve via `git log --oneline`
    314 > 3. **`git tag`**: With no args, outputs a plain alphabetical list of all tags
    315 > 4. **`-d v1.0`**: Removes the tag locally — does **not** affect the remote
    316 
    317 > [!warning]+ Tags Are Local Until Pushed
    318 > 1. Tags do not sync automatically with `git push`
    319 > 2. Push a single tag: `git push origin v1.0`
    320 > 3. Push all tags at once: `git push --tags`
    321 > 4. Remove a remote tag: `git push origin -d v1.0`
    322 
    323 ---
    324 
    325 ## Section 9 — Branch Management
    326 
    327 **`git branch` — Flags**
    328 
    329 | Flag | Effect |
    330 |---|---|
    331 | *(no args)* | List local branches; `*` marks current |
    332 | `-a` | List all local and remote-tracking branches |
    333 | `-r` | List remote-tracking branches only |
    334 | `-v` | Verbose: show last commit hash + message per branch |
    335 | `-d <name>` | Delete branch (safe; refuses if unmerged) |
    336 | `-D <name>` | Force-delete regardless of merge status |
    337 | `-m <old> <new>` | Rename a branch |
    338 | `--merged` | List branches already merged into current |
    339 | `--no-merged` | List branches not yet merged |
    340 
    341 ```bash
    342 # See all local branches (* = current)
    343 git branch
    344 
    345 # See all branches including remotes
    346 git branch -a
    347 
    348 # See last commit per branch
    349 git branch -v
    350 
    351 # Delete a merged branch (safe)
    352 git branch -d style
    353 
    354 # Force-delete an unmerged branch
    355 git branch -D experiment
    356 
    357 # List branches already merged into main (safe to delete)
    358 git branch --merged main
    359 ```
    360 
    361 > [!warning]+ Deleting Branches
    362 > 1. `git branch -d` refuses to delete a branch with unmerged changes — this is a safety net
    363 > 2. `git branch -D` force-deletes regardless — use only when you are certain the data is not needed
    364 > 3. Deleting a remote branch with `git push origin --delete` is permanent — GitHub has no recycle bin
    365 
    366 ---
    367 
    368 ## Section 10 — Creating and Switching Branches (git switch)
    369 
    370 > [!info]+ [git switch](https://git-scm.com/docs/git-switch) Overview
    371 > Creates and/or switches between branches — introduced in Git 2.23 as a focused replacement for `git checkout`
    372 > 1. `-c` flag creates a new branch and switches in a single step
    373 > 2. Switching with uncommitted changes will fail unless Git can carry them safely
    374 > 3. Each branch maintains its own working tree state — files from other branches are hidden, not deleted
    375 > 4. Legacy equivalent: `git checkout -b <name>`
    376 
    377 **`git switch` — Flags**
    378 
    379 | Flag | Effect |
    380 |---|---|
    381 | *(branch name)* | Switch to existing local branch |
    382 | `-c <name>` | Create new branch and switch to it (from current HEAD) |
    383 | `-c <name> <start-point>` | Create from a specific branch or commit |
    384 | `-C <name>` | Force-create: resets branch if it already exists |
    385 | `--detach` | Switch to a commit directly (detached HEAD state) |
    386 | `-` | Switch back to the previously checked-out branch |
    387 
    388 ```bash
    389 # Confirm which branch you're on before creating
    390 git branch
    391 
    392 # Create new branch from current HEAD and switch to it
    393 git switch -c style
    394 
    395 # Switch to an existing branch
    396 git switch main
    397 
    398 # Create branch from a specific past commit
    399 git switch -c hotfix abc1234
    400 
    401 # Jump back to the previous branch
    402 git switch -
    403 ```
    404 
    405 > [!faq]+ git switch vs git checkout
    406 > 1. `git switch` (Git 2.23+) handles **branch operations only** — cleaner, less ambiguous
    407 > 2. `git checkout` handles branches **and** file restoration — can be confusing
    408 > 3. Legacy equivalent: `git checkout -b <name>` = `git switch -c <name>`
    409 > 4. *Both commands still work — `git switch` is preferred in modern workflows*
    410 
    411 ---
    412 
    413 ## Section 11 — Merging Branches
    414 
    415 > [!info]+ [git merge](https://git-scm.com/docs/git-merge) Overview
    416 > Integrates commits from one branch into the current branch, preserving full commit history
    417 > 1. Always switch to the **target** (receiving) branch before merging
    418 > 2. Fast-forward merges create no new commit; merge commits have two parents
    419 > 3. Conflicts require manual resolution of `<<<<<<<` / `=======` / `>>>>>>>` markers
    420 > 4. Git 2.34+ uses the `ort` strategy by default instead of `recursive`
    421 
    422 **`git merge` — Flags**
    423 
    424 | Flag | Effect |
    425 |---|---|
    426 | *(branch name)* | Merge named branch into current branch |
    427 | `--no-ff` | Always create a merge commit (preserves branch history) |
    428 | `--ff-only` | Abort if fast-forward is not possible |
    429 | `--squash` | Combine all source commits into one unstaged change |
    430 | `--abort` | Cancel an in-progress conflicted merge |
    431 | `--continue` | Resume merge after resolving conflicts |
    432 | `-m "<msg>"` | Override the auto-generated merge commit message |
    433 
    434 ```bash
    435 # Standard merge — bring style into main
    436 git switch main
    437 git merge style
    438 
    439 # Force a merge commit even if fast-forward is possible
    440 git merge --no-ff style -m "Merge style feature"
    441 
    442 # Fast-forward only — abort if not possible
    443 git merge --ff-only style
    444 
    445 # Squash all commits from style into one clean commit
    446 git merge --squash style
    447 git commit -m "Add styling feature"
    448 
    449 # Abort a merge gone wrong
    450 git merge --abort
    451 
    452 # After resolving conflicts manually
    453 git add <resolved-file>
    454 git merge --continue
    455 ```
    456 
    457 > [!info]+ Merge Output Interpretation
    458 > 1. `Fast-forward` — branch pointer advanced; no new commit created
    459 > 2. `Merge made by the 'ort' strategy` — merge commit created; histories had diverged
    460 > 3. `CONFLICT (content): Merge conflict in <file>` — manual resolution required
    461 > 4. `Already up to date.` — source branch has no commits not already in target; nothing to do
    462 
    463 > [!warning]+ Merge Safety Considerations
    464 > 1. Merge commits are visible in `git log` — use `--squash` or `--ff` to reduce noise in history
    465 > 2. Merging directly into `main` without a pull request is not recommended in team workflows
    466 > 3. Accidental merge recovery: `git reset --hard HEAD~1` — **use with extreme caution**
    467 
    468 ---
    469 
    470 ## Section 12 — Restoring Deleted or Lost Files
    471 
    472 > [!tip]+ Best All-in-One Fix — Force Sync with GitHub
    473 > When in doubt, this restores your branch to exactly match the remote:
    474 > ```bash
    475 > git fetch --all
    476 > git reset --hard origin/HTB-Labs   # Replace with your branch name
    477 > ```
    478 
    479 **Recovery Decision Table**
    480 
    481 | Situation | Command | Risk |
    482 |---|---|---|
    483 | Deleted, not yet staged | `git restore .` | None — safe |
    484 | Deleted and staged, not committed | `git restore --staged --worktree .` | None — safe |
    485 | Committed locally, not pushed | `git reset --hard HEAD~1` | Low — local only |
    486 | Committed and pushed | `git fetch --all` then `git reset --hard origin/<branch>` | Medium — confirm first |
    487 
    488 ```bash
    489 # Scenario 1 — Deleted files, not yet staged
    490 git restore .
    491 
    492 # Scenario 2 — Deleted and staged, NOT yet committed
    493 git restore --staged --worktree .
    494 
    495 # Scenario 3 — Deleted, committed, NOT yet pushed
    496 git reset --hard HEAD~1   # Roll back 1 commit; replace 1 with number of commits to undo
    497 
    498 # Scenario 4 — Deleted, committed AND pushed
    499 git fetch --all
    500 git reset --hard origin/main   # Replace main with your branch name
    501 ```
    502 
    503 > [!info]+ Command Breakdown
    504 > 1. **`git restore .`**: Discards all unstaged changes — safe, only affects uncommitted/unstaged changes
    505 > 2. **`git restore --staged --worktree .`**: Combines unstaging and file restoration in a single command
    506 > 3. **`git reset --hard HEAD~1`**: Resets both commit history and working directory to one commit before HEAD — safe because the bad commit has not been pushed
    507 > 4. **`git fetch --all`**: Downloads all latest data from every remote branch without merging
    508 > 5. **`git reset --hard origin/main`**: Forces local branch to exactly match the remote state
    509 
    510 > [!warning]+ Destructive Operation
    511 > `git reset --hard` permanently discards local changes and commits ahead of the reset point. Ensure you do not need that data before running this command.
    512 
    513 ---
    514 
    515 ## Section 13 — Branch Naming Conventions
    516 
    517 > [!tip]+ Naming Rules
    518 > Keep names clean, lowercase, no spaces — use hyphens `-` as separators
    519 
    520 | Vault / Purpose | Good Branch Name |
    521 |---|---|
    522 | Personal Obsidian vault | `main` or `personal-vault` |
    523 | HTB / CTF notes | `HTB-Labs` |
    524 | Work notes | `work-notes` |
    525 | Study notes | `study-vault` |
    526 | Railway site edits | `site-edits` |
    527 | New feature / test | `feature/new-template` |
    528 | Bug / fix | `bugfix/broken-link` |
    529 | Archive / old version | `archive/2024-vault` |
    530 
    531 ---
    532 
    533 ## Section 14 — Master Quick Reference Card
    534 
    535 ```bash
    536 # ── DIAGNOSE ──────────────────────────────────────────
    537 git status                           # See uncommitted changes + current branch
    538 git branch                           # List local branches (* = active)
    539 git branch -a                        # List all branches including remotes
    540 git branch -v                        # See last commit per branch
    541 git log --oneline --graph --decorate --all  # Full history visualisation
    542 git log --oneline -5                 # Last 5 commits compact
    543 
    544 # ── CREATING ──────────────────────────────────────────
    545 git checkout --orphan branch-name    # New empty branch (no history, no files)
    546 git rm -rf .                         # Wipe files after orphan create (required)
    547 git checkout -b branch-name          # New branch inheriting current working state
    548 git switch -c branch-name            # Modern equivalent of checkout -b
    549 
    550 # ── SWITCHING ─────────────────────────────────────────
    551 git checkout branch-name             # Switch to vault/branch
    552 git switch branch-name               # Modern equivalent
    553 git checkout -                       # Jump back to previous branch
    554 git switch -                         # Modern equivalent
    555 
    556 # ── SAVING ────────────────────────────────────────────
    557 git add .                            # Stage all changes
    558 git commit -m "your message"         # Commit changes
    559 git push                             # Push to GitHub
    560 git push -u origin branch-name      # First push of a new branch
    561 
    562 # ── SYNCING ───────────────────────────────────────────
    563 git pull                             # Pull latest from GitHub
    564 git fetch --all                      # Fetch all remote branches (no merge)
    565 
    566 # ── RESTORING ─────────────────────────────────────────
    567 git restore .                        # Undo unstaged deletions (safe)
    568 git restore --staged --worktree .    # Undo staged deletions (safe)
    569 git reset --hard HEAD~1              # Roll back 1 commit (local only)
    570 git reset --hard origin/branch-name  # Force match GitHub (destructive)
    571 
    572 # ── TAGGING ───────────────────────────────────────────
    573 git tag -a v1.0 -m "Release"        # Create annotated tag
    574 git tag                              # List all tags
    575 git push origin v1.0                 # Push single tag to GitHub
    576 git push --tags                      # Push all tags to GitHub
    577 git tag -d v1.0                      # Delete local tag
    578 git push origin -d v1.0             # Delete remote tag
    579 
    580 # ── MERGING ───────────────────────────────────────────
    581 git switch main                      # Switch to target branch first
    582 git merge branch-name                # Merge branch into current
    583 git merge --no-ff branch-name        # Force merge commit
    584 git merge --squash branch-name       # Squash into one commit
    585 git merge --abort                    # Cancel conflicted merge
    586 
    587 # ── CLEANUP ───────────────────────────────────────────
    588 git branch -d branch-name            # Delete local branch (safe)
    589 git branch -D branch-name            # Force delete local branch
    590 git push origin --delete branch-name # Delete remote branch (permanent)
    591 git branch -m old-name new-name      # Rename a branch
    592 ```
    593 
    594 ---
    595 
    596 ## References
    597 
    598 | Category | Resource | URL |
    599 |---|---|---|
    600 | Core Docs | Git Official Documentation | [git-scm.com/doc](https://git-scm.com/doc) |
    601 | Core Docs | git-checkout | [git-scm.com/docs/git-checkout](https://git-scm.com/docs/git-checkout) |
    602 | Core Docs | git-branch | [git-scm.com/docs/git-branch](https://git-scm.com/docs/git-branch) |
    603 | Core Docs | git-reset | [git-scm.com/docs/git-reset](https://git-scm.com/docs/git-reset) |
    604 | Core Docs | git-restore | [git-scm.com/docs/git-restore](https://git-scm.com/docs/git-restore) |
    605 | Core Docs | git-switch | [git-scm.com/docs/git-switch](https://git-scm.com/docs/git-switch) |
    606 | Core Docs | git-merge | [git-scm.com/docs/git-merge](https://git-scm.com/docs/git-merge) |
    607 | Core Docs | git-log | [git-scm.com/book — Viewing History](https://git-scm.com/book/en/v2/Git-Basics-Viewing-the-Commit-History) |
    608 | Core Docs | git-tag | [git-scm.com/book — Tagging](https://git-scm.com/book/en/v2/Git-Basics-Tagging) |
    609 | Core Docs | Basic Branching and Merging | [git-scm.com/book — Branching](https://git-scm.com/book/en/v2/Git-Branching-Basic-Branching-and-Merging) |
    610 | Tutorials | git log Tutorial | [atlassian.com/git/tutorials/git-log](https://www.atlassian.com/git/tutorials/git-log) |
    611 | Tutorials | git tag Tutorial | [atlassian.com/git/tutorials — tag](https://www.atlassian.com/git/tutorials/inspecting-a-repository/git-tag) |
    612 | Tutorials | git switch — Git Tower | [git-tower.com/learn/git/commands/git-switch](https://www.git-tower.com/learn/git/commands/git-switch) |
    613 | GitHub | Managing Branches | [docs.github.com — Managing Branches](https://docs.github.com/en/repositories/configuring-branches-and-merges-in-your-repository/managing-branches-in-your-repository) |
    614 | GitHub | About Branches | [docs.github.com — About Branches](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/about-branches) |
    615 | Deployment | Railway Docs — Deployments | [docs.railway.app/deploy/deployments](https://docs.railway.app/deploy/deployments) |
    616 | App | Obsidian Official Site | [obsidian.md](https://obsidian.md/) |
    617 | Cheatsheets | Atlassian Git Cheat Sheet | [Atlassian PDF](https://wac-cdn.atlassian.com/dam/jcr:e7e22f25-bba2-4ef1-a197-53f46b6df4a5/SWTM-2088_Atlassian-Git-Cheatsheet.pdf) |
    618 | Cheatsheets | GitLab Git Cheat Sheet | [GitLab PDF](https://about.gitlab.com/images/press/git-cheat-sheet.pdf) |
    619 
    620 ---
    621 
    622 #Git #GitHub #Obsidian #Railway #VersionControl #Workflow #BranchManagement #OrphanBranch #Branching #Merging #Tagging #GitLog #GitSwitch #GitMerge