# git-commit-push

Git commit and push quick reference for this repository.

Use this skill when the task is about staging changes, creating commits, pushing branches, amending commits, stashing work, or inspecting git history.

## Basic Flow

### Inspect changes
```bash
git status
git diff
git diff --cached
```

### Stage changes
```bash
git add .
git add <path>
git add -p
```

### Commit
```bash
git commit -m "feat: short summary"
git commit
git commit -am "fix: short summary"
```

## Push
```bash
git push
git push origin main
git push -u origin <branch>
git push --force-with-lease
```

## Amend
```bash
git commit --amend -m "new message"
git add <missed-file>
git commit --amend --no-edit
```

If the amended commit has already been pushed:

```bash
git push --force-with-lease
```

## Undo and Restore
Prefer non-destructive commands unless the user explicitly asks otherwise.

### Unstage
```bash
git restore --staged <path>
git reset HEAD <path>
```

### Discard worktree changes
```bash
git restore <path>
```

### Undo commits while keeping changes
```bash
git reset --soft HEAD~1
git reset HEAD~1
```

Avoid `git reset --hard` unless the user explicitly requests destructive history/worktree reset.

## Stash
```bash
git stash
git stash -u
git stash list
git stash pop
git stash apply stash@{0}
git stash drop stash@{0}
```

## History
```bash
git log
git log --oneline
git log --graph --oneline --all
git log -n 5
git log <path>
```

## Conflict Handling
```bash
git status
git checkout --ours <path>
git checkout --theirs <path>
git add <path>
git commit -m "resolve merge conflict"
git merge --abort
```

## Commit Message Guidance
- Prefer conventional prefixes such as `feat:`, `fix:`, `refactor:`, `docs:`, `test:`, `chore:`.
- Keep the first line concise and user-impact oriented.
- Do not amend or force-push unless the user asked for it or the workflow clearly requires it.
