# Version Control

{% hint style="warning" %}
Command line git is unavailble because of a licensing issue. Use lg2 or the GUI instead.
{% endhint %}

### Set up your identities

Git uses name and email address identify the author of each commit. Before making a commit, you'll need to set up your identity.

To proceed, go `Settings > Version Control > Identity`.&#x20;

### Set up your credentials

If you are cloning a private repository or pushing changes to a remote, you'll need to set up credentials. To start, enter your credentials at `Settings > Version Control > Authentication`.

#### Password-based Authentication

The easiest way to authenticate in Git is to use password-based authentication. To start, obtain a personal access token from your Git hosting provider. To learn more:

{% embed url="<https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token>" %}
Creating a personal access token on GitHub
{% endembed %}

{% embed url="<https://docs.gitlab.com/ee/user/profile/personal_access_tokens.html>" %}
Creating a personal access tokeno on GitLab
{% endembed %}

#### Key-based Authentication

SSH keys can also be used to authenicate in Git. To start, generate a SSH key pair and configure them in your Git hosting provider. To learn more:

{% embed url="<https://docs.github.com/en/authentication/connecting-to-github-with-ssh>" %}
Connecting to GitHub with SSH keys
{% endembed %}

{% embed url="<https://docs.gitlab.com/ee/user/ssh.html>" %}
Connecting to GitLab with SSH keys
{% endembed %}

#### Setting up multiple credentials

Code App supports multiple credentials. You can configure a unique credential for each hosting provider by specifying their hostnames during the setup process.

<figure><img src="https://2795973332-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FzNRZttJUHODcLjBFRZHP%2Fuploads%2Frv1LMFCLuIg8ZmdJA9RT%2FSimulator%20Screenshot%20-%20iPad%20(10th%20generation)%20-%202023-08-24%20at%2012.54.27.png?alt=media&#x26;token=aeab4f40-e028-4482-a219-3cc1fbec6977" alt=""><figcaption><p>Hostname-based credentials</p></figcaption></figure>

### Cloning a repository

To clone a repository, tap the source control icon in the sidebar and enter its url in the clone repository section. Assign it as the workspace folder by tapping the open folder button.

{% hint style="info" %}
Workspace folder is the folder the editor currently loaded. To work with a git repository, it must be located at the root of the workspace folder. You can load a folder by holding a folder cell in explorer or by using the `code` command in the terminal.
{% endhint %}

<figure><img src="https://2795973332-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FzNRZttJUHODcLjBFRZHP%2Fuploads%2FDpfaVZHrgZt1KKG5tiJ9%2FSimulator%20Screenshot%20-%20iPad%20(10th%20generation)%20-%202023-08-24%20at%2012.56.17.png?alt=media&#x26;token=95d4e31d-8b97-40b8-9137-b93457267d65" alt=""><figcaption><p>Cloning a repository</p></figcaption></figure>

#### Community Templates

A list of community-maintained projects for Code App can be found and cloned under the community templates section.

### Committing files

Newly added / modified files must be added to the staging area before you can make a commit. To do this, press the plus icon next to the file name.

![Adding a file to staging area](https://2795973332-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FzNRZttJUHODcLjBFRZHP%2Fuploads%2FX2Ps0tNAqAFStOJTZnwy%2FSimulator%20Screenshot%20-%20iPad%20\(10th%20generation\)%20-%202023-08-24%20at%2013.00.09.png?alt=media\&token=40dcebe6-93aa-499e-ad58-5e779cd7e899)

You can now enter a commit message in the textfield and press the commit button to commit. You can also use the `command`+`enter` shortcut.

### Pushing to remote

You can push your changes to your hosting provider like GitHub.

![Pushing changes to remote](https://2795973332-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FzNRZttJUHODcLjBFRZHP%2Fuploads%2F5PXREqzdhPFKfIB0lBeG%2FSimulator%20Screenshot%20-%20iPad%20\(10th%20generation\)%20-%202023-08-24%20at%2013.00.47.png?alt=media\&token=277e8fa7-d721-4d83-abf8-4b0d258c56f5)

### Branches and tags

To checkout a branch or a tag, tap the branch icon located in the bottom left corner and select one.

![Checkout to a branch](https://2795973332-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FzNRZttJUHODcLjBFRZHP%2Fuploads%2Fh7ezqKolNf6lv9aMETU6%2FSimulator%20Screenshot%20-%20iPad%20\(10th%20generation\)%20-%202023-08-24%20at%2012.57.21.png?alt=media\&token=b3df5fa3-ef98-491a-9bd3-d71164a0796c)

### Pull and Fetch

You can also pull or fetch changes from remote. Pull immediately applies the upstream changes to your files. It does so by fast-forwarding the upstream commits if possible or attempting to merge otherwise. On the other hand, fetch does not write changes to your files.

<figure><img src="https://2795973332-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FzNRZttJUHODcLjBFRZHP%2Fuploads%2FkIAlR4A4qIG5QR273t48%2FSimulator%20Screenshot%20-%20iPad%20(10th%20generation)%20-%202023-08-24%20at%2012.53.29.png?alt=media&#x26;token=2ee0ba11-d190-4892-9ec2-28d3cc0df8f5" alt=""><figcaption><p>Pull from a remote</p></figcaption></figure>

To learn more about git pull and fetch:

{% embed url="<https://git-scm.com/docs/git-pull>" %}

{% embed url="<https://git-scm.com/docs/git-fetch>" %}
