All pages
Powered by GitBook
1 of 1

Loading...

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.

If the repository is not empty, you can copy the HTTPS link by:

  1. Clicking on the "code" section on the GitHub repository page

  2. Clicking “code” button

  3. Clicking “HTTPS”

  4. Clicking the clipboard icon

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

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

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

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 ). Code collaborators can create different versions of the same repository by creating new branches diverging from the master branch (see ). Every branch, including master, keeps track of the changes explicitly committed to it..

Git add marks the files you want to include in the next commit (see ). Using “git add --all” marks all files in the current directory. For more Git add options see . At a high level, Git commit stores a “snapshot” of the state of marked files to save to the branch (see article). Finally “git push” transfers your commit to your remote repository (see article).

Git pull fetches and merges the latest commit of the branch your local workspace is currently on. For more on Git pull see documentation.

Git branches guide
Git branches guide
Git add guide
Git add guide
this
this
this