# Git commands

Everyday commands for reviewing work, making commits and sharing a branch.
Replace names such as `feature/my-change` and `path/to/file` with your own values.
KeyCrumb only displays these commands; run them yourself in your terminal.

## Review your work

### Working tree and staging status

```sh
git status --short --branch
```

### Changes not yet staged

```sh
git diff
```

### Changes ready for the next commit

```sh
git diff --staged
```

### Recent history

```sh
git log --oneline --decorate -10
```

## Branch and commit

### Create a branch from your current commit

```sh
git switch -c feature/my-change
```

### Stage one file

```sh
git add path/to/file
```

### Review and stage individual changes

```sh
git add --patch
```

### Commit staged changes

```sh
git commit -m "Describe the change"
```

## Collaborate

### List remotes

```sh
git remote -v
```

### Fetch remote history

Updates remote-tracking branches without changing your working files.

```sh
git fetch origin
```

### Update your current branch by fast-forward only

Stops if a merge would be needed.

```sh
git pull --ff-only
```

### Publish your current branch and set its upstream

```sh
git push --set-upstream origin HEAD
```

## Keep unfinished work

### Stash tracked and untracked changes

```sh
git stash push --include-untracked -m "Work in progress"
```

### List saved stashes

```sh
git stash list
```

### Apply the latest stash while keeping the saved copy

Can produce conflicts; resolve them before continuing.

```sh
git stash apply
```

## Unstage a file

Keeps the working copy changes.

```sh
git restore --staged path/to/file
```

Reference: [Git’s everyday guide](https://git-scm.com/docs/giteveryday) and
[command reference](https://git-scm.com/docs).
