Branches and remotes
Checkout of branches, remote branches, tags and commits
5 min read
Checkout switches the branch you're working on: the working directory gets that branch's files and the next commits go into it. In Versora, checking out a remote branch also takes care of the matching local branch. It creates the branch if it doesn't exist, fast-forwards it if it's behind and asks what to do if the two have diverged.
- Double-click the branch in the LOCAL section or its label in the graph.
- The branch's menu: Check out feature/login.
- The branch's menu › the Checkout submenu › the branch's name.
- Palette (Ctrl+P): "Check out branch…" (detail: "Lists local and remote
branches"). The command fills the search with
checkoutand shows only branches. - Palette with a prefix: type
checkoutorcoand the branch name. The items show up as "Local branch" or "Remote branch".
- Double-click the
feature/loginbranch in the LOCAL section. - The bar shows "Checking out feature/login…".
- At the end, the current branch gets the check mark in the panel and its name shows up in the repository bar (repository › branch).
git checkout feature/login --
The -- at the end makes sure the name is read as a branch, even if there's a file with the same
name.
Ctrl+Z undoes "Check out feature/login" and goes back to the previous branch. Undo refuses if you edited files after the checkout.
A remote branch (origin/feature/sso) doesn't take commits directly: to work on it you need a local
branch. Versora decides what to do based on the state of the local branch with the same name.
- Double-click the branch in the REMOTE section or the
origin/…label in the graph. - The remote branch's menu: Check out feature/sso.
- A local branch's menu › the Checkout submenu ›
origin/feature/sso(the remote branch with the same name). - Palette: "Check out branch…" and choose a "Remote branch" item.
State of the local branch feature/sso | What Versora does |
|---|---|
| Doesn't exist | Creates the local branch tracking origin/feature/sso and checks it out. |
| Exists and is behind the remote | Checks it out and fast-forwards the branch to the remote, in the same step. Notice: "feature/sso moved 3 commits forward to origin/feature/sso (fast-forward)". |
| Same as or ahead of the remote | Just checks it out. The local commits stay. |
| The two have diverged | Asks what to do (see below). |
Diverging means the local branch has commits the remote doesn't have, and the remote has commits the local one doesn't have. That happens, for example, after a colleague force pushed. In that case the Local branch feature/sso has diverged dialog opens, with the count: "only the local one has 2 commits, and only origin/feature/sso has 5 commits".
| Choice | What it does | What git runs |
|---|---|---|
| Check out feature/sso as it is | The local commits stay. Afterwards you can pull to bring in the remote. | git checkout feature/sso -- |
| Create a new branch here | Creates a new branch at the remote's commit; the local one is left untouched. The suggested name is feature/sso-origin, and you can change it in New branch name. | git checkout --no-track -b feature/sso-origin refs/remotes/origin/feature/sso |
| Reset feature/sso to origin/feature/sso | The local branch now points to the remote's commit. The local commits leave the branch. | git checkout --no-track -B feature/sso refs/remotes/origin/feature/sso |
After the reset, the notice "feature/sso now points to origin/feature/sso" shows up.
# the local branch doesn't exist
git checkout -b feature/sso --track origin/feature/sso
# the local branch exists and is behind (fast-forwards in the same step)
git checkout --no-track -B feature/sso refs/remotes/origin/feature/sso
checkout -B moves the branch and switches the files at once: if switching the files fails, nothing
changes. --no-track keeps the upstream the branch already had.
Ctrl+Z undoes the whole checkout: the created branch is deleted, the fast-forwarded or reset branch goes back to the previous commit and HEAD goes back to the previous branch. With the reset, the local commits that "left" come back to the branch.
To see how the project was at an old commit or at a published version, check out the commit. HEAD becomes "loose" (detached): it points to the commit, not to a branch.
- A commit's menu: Check out this commit.
- A branch's menu › the Checkout submenu › this commit (the tip commit, without the branch).
- A tag's menu: Check out the commit at v1.4.0.
- Double-click a tag in the TAGS section.
The repository bar shows "detached HEAD @ 3f2a9c1" in place of the branch name, highlighted. Pull, push and Sync are unavailable until you go back to a branch.
If you want to keep commits made in that state, create a branch there: the commit's menu › Create branch here… (see Create branch).
git checkout 3f2a9c1 --
git checkout <commit of the v1.4.0 tag> --
By default, checkout takes along the changes that don't conflict with the destination branch. When some change would be overwritten, git refuses the switch. In that case the error notice says: "You can check out with autostash: the changes go to a stash and come back after the switch." and offers Check out with autostash.
With checkout autostash turned on in Preferences, that always happens, without asking. The details, including what happens when the changes come back with a conflict, are in Autostash.
- From the merge requests panel: the MR's menu › Check out feature/login. It fetches from the remote first, if the branch hasn't been downloaded yet (see MERGE REQUESTS section).
- From an issue: Start work… creates the branch and checks it out right away (see Start work).
- From a worktree: a branch checked out in another worktree can't be checked out here. Use the branch's menu to open that worktree (see Worktrees).
- "The remote branch origin/feature/sso no longer exists. Fetch and try again.": the branch disappeared from the remote (the merge request went in and the branch was removed, for example). Fetch to update the list.
- ""feature sso" isn't a valid branch name.": the name typed in Create a new branch here isn't accepted by git.
- "You can check out with autostash…": there are local changes that would be overwritten. Use the notice's button, commit or stash first.
- "Wait for the current operation to finish.": another operation is running in this repository.
- Preferences › Operations › Pull, checkout and push › Autostash › On checkout (off by default).