# Git

Review changes, commit, and work with branches, stashes, and tags.

Every Lyna project is a Git repository. The **Source Control** view lets you review what changed, commit it, work on branches, and set work aside with stashes. You do not need a GitHub account for any of this.

The Source Control view with one staged file, one changed file and a commit message, and the changes of the changed file open beside it.

## What you can do

- See every changed file and open its diff.
- Stage, unstage and discard changes, one file or all at once.
- Write a commit message yourself or with AI, and amend the last commit.
- Create, switch, merge and delete branches.
- Stash work in progress and bring it back later.
- Tag a commit to mark a release.
- Keep your commits saved in the cloud with your project.

## Open Source Control

In **Code** mode, choose **Source Control** in the views rail, or press `Cmd/Ctrl + Shift + H`.

The view has the branch picker at the top, then the commit box, then your changes grouped as **Merge conflicts**, **Staged** and **Changes**, then the **Graph**, **Tags** and **Stashes** sections. The footer shows the cloud sync state.

## Review your changes

- Click a file to open its diff (**Open changes**). `Shift` or `Cmd`/`Ctrl` click selects several files without opening them.
- Rest the pointer on a file to preview its changes. Under the diff, each block of changes has **Stage Hunk** and **Revert Hunk**, or **Unstage Hunk** for a staged file, so a commit can take part of a file. **Revert Hunk** puts the old lines back after a second click on **Confirm Revert**.
- Hover a file for **Stage**, **Unstage** or **Discard**. Use **Stage all**, **Unstage all** or **Discard all** on a group.
- Right-click a file for **Open file**, **Copy path** and **Reveal in explorer**.

From the keyboard: arrows move, `Space` selects, `Shift` + arrows extend the selection, `Enter` opens the diff, and `Delete` discards.

## Review all changes in one page

Choose **Open All Changes** at the top of Source Control, or run it from the command palette, to read every changed file in one page in place of your tabs. **Open Staged Changes** shows only what your next commit takes, and **Open Changes** on a commit of the graph shows what that commit changed.

The changes page of a commit opened from the graph, with the commit title, its file count and line counts at the top, then each changed file as a section with its diff.

- Each file is a section you can collapse, with its counts of added and removed lines and **Open File**.
- The buttons at the top hide the changes that are only whitespace and wrap long lines, the same two options as every diff.
- The page follows your work: stage, discard or edit a file and its section updates.
- `Alt + Up` and `Alt + Down` move from file to file. Press `Escape` to close the page.
- Point at a line of the new code and choose the **+** beside it (**Add a note**) to leave a note for your team or Lyna AI on those lines. See [Annotate](/features/collaborate/annotate#notes-on-code).

**Review changes since main**, at the top of Source Control or in the command palette, opens the same page on every change since main, committed or not, with a **Compare with** picker. **Run Agent Review** opens it and starts a review that finds issues in those changes. See [Agent Review](/features/code/agent-review).

## Commit

1. ### Stage what goes in

   Stage the files for this commit. If you stage nothing, you can commit every change at once.
2. ### Write the message

   Type in **Describe what changed**. Pick a **Commit type** (`feat`, `fix`, `docs`, `style`, `refactor`, `perf`, `test`, `build`, `ci`, `chore` or `revert`) to add it as a prefix, or keep **No type**. A counter shows the length of the first line: keep it short, and under 72 characters.

   Choose **Write with AI** to get a message written from your changes.
3. ### Commit

   Choose **Commit N staged files**, or **Commit all N files** from the button menu. You can also press `Cmd/Ctrl + Enter` in the message box.

To change the last commit, turn on **Amend last commit**. Leave the message empty to keep the last message.

> [!NOTE]
>
> **Write with AI uses credits**
>
> When your AI credits run out, connect your own API key or upgrade to Pro to keep writing messages with AI. See [Plans and credits](/introduction/plans-and-credits).

## Branches

Open the branch picker at the top of the view. Type in **Find a branch** to filter, then:

- **Switch to** a branch.
- **New branch**, or **New branch from** another branch or commit.
- **Merge a branch into this one**.
- **Delete a branch**.
- **Assign to me** or **Unassign**, to show your team who works on a branch.
- **Refresh branches**.

If you have uncommitted changes when you switch, choose **Commit, then switch**, **Stash, then switch** or **Discard and switch**.

## Merge and resolve conflicts

1. ### Choose a branch

   Choose **Merge a branch into this one** and pick the source branch. Turn on **Delete branch after merge** if you are done with it.
2. ### Resolve conflicts

   If both branches changed the same lines, the merge stops at **Resolve conflicts**. For each conflicted file, pick the **Current** or **Incoming** version, or edit the file, then choose **Mark as Resolved**.

   For a file with many conflicts, choose **Open in Merge Editor** in the conflicts list, or on the file's row in **Merge conflicts**. The merge editor shows **Incoming** and **Current** side by side and the **Result** below, which you can edit. Each conflict has **Accept Incoming**, **Accept Current**, **Accept Both** and **Ignore**. Move between conflicts with **Next Conflict** and **Previous Conflict**, start over with **Reset Result**, and choose **Complete Merge** to save the result and stage the file.
3. ### Finish

   Choose **Complete Merge**. To cancel instead, choose **Abort Merge**.

## Stashes and tags

- **Stashes**: choose **Stash** to set your changes aside, with an optional message. Later, **Pop** applies a stash and removes it, **Apply** keeps it, and **Drop** deletes it.
- **Tags**: choose **New tag** and enter a name such as `v1.0.0`. Add a message to make an annotated tag. Deleting a tag keeps the commit.

## Cloud sync

Your commits are saved in the cloud with your project, so they are there when you open the project again or from another computer. This is Lyna storage, not GitHub. To use GitHub, see [GitHub and pull requests](/features/code/github-and-pull-requests).

The footer shows how many commits are waiting to be pushed or pulled, with **Push**, **Pull** and **Sync**.

- **Local commits are not saved to the cloud yet**: choose **Save now**.
- **Branches have diverged**: your local history and the cloud version have different commits. Choose **Keep mine** to overwrite the cloud version, or **Take theirs** to restore the cloud version. Taking theirs drops your uncommitted changes.

> [!WARNING]
>
> **History size**
>
> The Git history of a project can be up to 1 GB. If it grows past that, remove large files such as images and videos from the history.

## Who can do what

People with view access can see changes and history. Depending on the project, they may pull the latest cloud version, but they cannot push or commit. Only editors can commit, create, merge or delete branches, and resolve a divergence.

## Shortcuts

| Action                     | Shortcut                              |
| -------------------------- | ------------------------------------- |
| Open Source Control        | `Cmd/Ctrl + Shift + H`                |
| Commit                     | `Cmd/Ctrl + Enter` in the message box |
| Open the diff of a file    | `Enter`                               |
| Discard the selected files | `Delete`                              |

## FAQ

### Do my commits go to GitHub?

No. Commits stay in your project and are saved to Lyna cloud storage. Link a repository in the GitHub view to push them to GitHub.

### Does the AI commit for me?

When the AI finishes a change, Lyna saves a checkpoint, so you can go back to it in [Version history](/features/projects/version-history). Your own commits are made from this view.

### How do I go back to an earlier commit?

Open the [branch graph](/features/code/branch-graph), open the commit's actions and choose **Restore to this commit**. A new commit records the restore, so nothing is lost.

## Related

- [Branch graph](/features/code/branch-graph): See your history as a graph and act on any commit.
- [Agent Review](/features/code/agent-review): Find issues in your changes before you commit or merge.
- [GitHub and pull requests](/features/code/github-and-pull-requests): Push to GitHub and open pull requests.
- [Local history](/features/code/local-history): Go back to an earlier save of a file.
