# Git

# Activating an SSH Key

```
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/server
```

# Order Of Operations

### Local &gt; remote

1. Add the changed files
2. commit the files
3. push to repo

```bash
git add FILE_NAME
git commit -m "message"
git push origin main
```

### Remote -&gt; local

1. Pull changes to local folder

```bash
git pull origin main
```

# General commands

### Force pull

```bash
git fetch origin
git reset --hard origin/main
```

### Stash changes

#### 1. Stash your changes

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-git-stash-push--m-%22m"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
</div></div></div><div class="overflow-y-auto p-4" dir="ltr">`git stash push -m <span class="hljs-string">"My local changes"</span>`</div></div>- `push` → saves your uncommitted changes to the stash stack.
- `-m "message"` → lets you label the stash so you know what it is later.

Now your working directory is clean.

---

#### 2. Pull the latest code (optional but recommended)

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-git-pull-origin-main"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
</div></div></div><div class="overflow-y-auto p-4" dir="ltr">`git pull origin main`</div></div>- `origin` → the name of your remote (default is usually `origin`).
- `main` → replace with your actual branch (could be `master`, `develop`, etc.).
- This ensures you’re up to date before pushing.

---

#### 3. Push your branch

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-git-push-origin-main"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
</div></div></div><div class="overflow-y-auto p-4" dir="ltr">`git push origin main`</div></div>- Sends your local commits to the remote repository.

---

#### 4. Re-apply your stashed changes (if you want them back)

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-git-stash-pop"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
</div></div></div><div class="overflow-y-auto p-4" dir="ltr">`git stash pop`</div></div>- This re-applies the last stashed set of changes and removes it from the stash list.
- If you want to keep the stash around, use `git stash apply` instead of `pop`.