---
title: "Git Branches and Remotes Cheatsheet | FindUtils"
description: "Create branches, inspect remote tracking, fetch updates, and use fast-forward merges. Check shared-branch rules before publishing changes."
url: https://findutils.com/cheatsheets/git-branches-remotes/
---

# Git Branches and Remotes Cheatsheet

Create branches, inspect remote tracking, fetch updates, and use fast-forward merges. Check shared-branch rules before publishing changes. 39 commands in 7 sections, filed under [Git & Version Control](https://findutils.com/cheatsheets/git/).

## Before a branch change

- `Check the project rules`: Some shared projects require all work on one branch
- `Commit or preserve your work`: Start a merge with a clean working tree
- `main, feature, origin`: Example names; replace them with your project names
- `Remote-tracking branch`: A local record of remote state, refreshed by fetch
- `Fast-forward only`: Update a branch only when its tip can move forward

## Inspect branches

- `git branch --show-current`: Print the current branch name; detached HEAD gives no name
- `git branch --list`: List local branches
- `git branch --remotes`: List local remote-tracking references
- `git branch --all`: List local and remote-tracking branches
- `git branch -vv`: Show branch tips and configured upstreams
- `git status --short --branch`: Show working state and available ahead or behind counts

## Create and switch

- `git branch feature`: Create feature at the current commit without switching
- `git switch feature`: Switch to an existing local branch
- `git switch -c feature`: Create a branch at HEAD and switch to it
- `git switch -c feature origin/main`: Start a new branch from the fetched remote reference
- `git switch --track origin/feature`: Create a local branch that tracks origin/feature

## Inspect and fetch remotes

- `git remote -v`: Show configured remote names and URLs
- `git remote get-url origin`: Read the fetch URL for origin
- `git remote show -n origin`: Show cached remote details without contacting the server
- `git fetch origin`: Fetch remote objects and update remote-tracking references
- `git fetch --all`: Fetch all configured remotes that permit this operation

## Compare before integration

- `git log HEAD..origin/main --oneline`: List fetched main commits absent from HEAD
- `git log origin/main..HEAD --oneline`: List local commits absent from fetched main
- `git diff --stat HEAD origin/main --`: Compare local and fetched file snapshots
- `git diff --name-only --diff-filter=U`: List paths that still have merge conflicts
- `git merge-base HEAD origin/main`: Find a common ancestor when one exists

## Integrate and publish

- `git merge --ff-only origin/main`: Fast-forward the current branch or refuse divergence
- `git pull --ff-only`: Fetch the upstream and require a fast-forward update
- `git merge feature`: Merge feature into the current branch; conflicts can stop it
- `git add -- <resolved-file>`: Stage a file after you resolve and review its conflicts
- `git merge --continue`: Finish an active merge after all conflicts are resolved
- `git push --dry-run origin feature`: Preview the remote update without sending it
- `git push -u origin feature`: Publish feature and set its upstream if the push succeeds

## Sources and related references

- `https://git-scm.com/docs/git-branch`: Check branch listing and upstream options
- `https://git-scm.com/docs/git-switch`: Check branch creation and switch behavior
- `https://git-scm.com/docs/git-fetch`: Check which remote references fetch updates
- `https://git-scm.com/docs/git-merge`: Check merge conditions and conflict handling
- `https://git-scm.com/docs/git-push`: Check push options and remote checks
- `/cheatsheets/git-history/`: Inspect the commits and changes before a merge

## Related

- Cheatsheet: [Git History and Diffs](https://findutils.com/cheatsheets/git-history/)
- Cheatsheet: [Gitignore Patterns](https://findutils.com/cheatsheets/gitignore-patterns/)
- Cheatsheet: [Git Commands](https://findutils.com/cheatsheets/git-commands/)
- Tool: [Env Merge](https://findutils.com/developers/env-merge/)
- Tool: [Merge ICS](https://findutils.com/convert/merge-ics/)
- Tool: [Merge Bookmarks](https://findutils.com/convert/merge-bookmarks/)
