# Remote Repo

Once you create a github account, you can start creating new remote repositories, and download them in you local machine and start working on them.

To create a new repo in github, go to + / new repository and there you start the process of creation.

You'll be asked the following indormation:

  • Name of the repo
  • Description
  • Whether it is public or private
  • Add README (file that describes the repo, contains dev instructions, etc)
  • Add .gitignore file (useful to ignore certain files)

# Cloning Remote Repo

Once the new repo is created, you can proceed to clone it, that means to download it in your local system, to be able to work on it.

In order to clone a github repository, click on the green button code, copy the https url, and in your local system, run the following command:

git clone https://github.com/your-user/repository-name.git

This will create a copy in our local system of the repo that we created in github.

From now on, this copy will be our local repo, which is a clone of the remote repo in github.

# Updating Local Repo

To keep a local repo updated with the remote repo, there are two commands: fetch and pull

# Fetching Branches

In order to take an existing branch in the remote repo to our local repo, you use the fetch command.

For instance, if you need to bring the develop branch, you run:

git fetch origin develop:develop

origin is the name of the remote repo, develop is the name of the branch you need to bring in from the remote repo, and :develop is the name you assign to that branch locally, that's usually the same name.

So now you have an exact copy of develop branch in your local repo, and you can start working on it.

# Updating Branches

In order to update a local branch with a remote branch, you use the pull command.

pull basically makes a fetch and a merge of the remote branch into your local branch.

For instance, if you need to update your local master branch with the remote master branch, you do the following:

git checkout master //to make sure you are positioned in master branch
git pull origin master

origin is the remote repo, and master is the branch you need to pull from the remote.

Once finished, the local master branch will be up-to-date with the latest state of the remote master brach, and you can start working on it.

# Pushing Branches

To upload to the remote repo a local branch, you need to use the push command.

push updates a remote branch with the commits of a local branch, or if this branch does not exist in the remote repo yet, it is created.

For instance, if you are working in a local branch named my-new-feature, which was created from master, or any other branch, and you need to upload that new branch to the remote repo, you run:

git push origin my-new-feature

origin is the name of the remote repo, and my-new-feature is the branch you need to push to the remote.

This will create a new branch in the remote repo called my-new-feature, that contains all the commits of the local branch.

Note: it is possible that you'll be asked for your github credentials the first time you make a push