# Syncing with a Local Workspace

Unless you created a repository from an existing local directory, The GitHub repositories created in previous sections are purely remote repositories. To sync these remote repositories with a local workspace you can clone your repository into a local directory. Once you clone your repository into a workspace, you can add changes on your local machine and then push them to your remote repository.

## Clone Repository

To clone your repository you first need an HTTPS link. If your repository is empty you can copy this from the top of your repository page.

![](https://927526918-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MLdLQiWusFChugCBdJh%2F-MMrHswA4P9JSPuHmqDV%2F-MMrxK5rlkAM4nSUAKZr%2FScreen%20Shot%202020-11-23%20at%201.10.15%20AM.png?alt=media\&token=f82b5023-3a42-418d-b947-6d1433891695)

If the repository is not empty, you can copy the HTTPS link by:&#x20;

1. Clicking on the "code" section on the GitHub repository page
2. Clicking “code” button
3. Clicking “HTTPS”
4. Clicking the clipboard icon

![](https://927526918-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MLdLQiWusFChugCBdJh%2F-MMrHswA4P9JSPuHmqDV%2F-MMrzBJAoDBSH6IjmAgu%2FScreen%20Shot%202020-11-23%20at%208.59.03%20PM.png?alt=media\&token=c6b9067c-7182-4598-bd26-90ae0ae6e4b6)

In the command line enter the following:

```
$ cd [your_local_workspace]
$ git clone [HTTPS link]
```

Now your remote repository is synced to your local workspace. All changes that are explicitly committed and pushed will be added to the remote repository.

## Pushing Local Changes

At a high level, Git performs Version Control for repositories through branches. Each repository has a master branch which is the mainline of the project (see [Git branches guide](https://git-scm.com/book/en/v2/Git-Branching-Branches-in-a-Nutshell)). Code collaborators can create different versions of the same repository by creating new branches diverging from the master branch (see [Git branches guide](https://git-scm.com/book/en/v2/Git-Branching-Branches-in-a-Nutshell)). Every branch, including master, keeps track of the changes explicitly committed to it..

To push local changes in your cloned repository to the current branch, enter the following commands in your cloned repository:

```
$ git add --all
$ git commit -m "your commit message"
$ git push
```

Git add marks the files you want to include in the next commit (see [Git add guide](https://github.com/git-guides/git-add)).  Using “git add --all” marks all files in the current directory. For more Git add options see [Git add guide](https://github.com/git-guides/git-add). At a high level, Git commit stores a “snapshot” of the state of marked files to save to the branch (see [this](https://www.atlassian.com/git/tutorials/saving-changes/git-commit) article). Finally “git push” transfers your commit to your remote repository (see [this](https://www.atlassian.com/git/tutorials/syncing/git-push) article).

## Updating the Local Workspace

When collaborating with others, you should always make sure you are working with the latest version of the repository before making local changes. To update your local workspace to the latest commit of the remote repository, enter the following command in your local workspace directory:

```
$ git pull
```

Git pull fetches and merges the latest commit of the branch your local workspace is currently on. For more on Git pull see [this](https://git-scm.com/docs/git-pull) documentation.

## &#x20;
