GitHub is the most popular web-based hosting service for computer source code. It's a website used by developers to work on software projects collaboratively every day. GitHub is very popular with open source software, and with advanced features for tracking and reporting issues.
In short, You as a developer can use GitHub to upload your Git repo and share it with the world for the price of zero.
Setup your GitHub
Go to https://github.com/join and register a GitHub account just like any other social media or Google services. Next, create a remote repo in GitHub by clicking the new button from the dashboard.
Once you complete the setup, you'll be given instructions on how to create and push your local repo to GitHub.
Let's get back to our local repo. On the repo directory, type
git remote add origin https://github.com/<username>/<repo-name>.git
Pushing and Pulling
Now that we have a remote repo, it's time to try and push our local repo to GitHub. The term pushing and pulling is used for updating repos. Pushing means we're updating remote repo to the current state of local repo, and vice versa for pulling. Please note that you need to push and pull into the right branch, or the history might get entangled between branches.
Now since we have added remote repo, let's push our local master branch into GitHub by running the following command:
$ git checkout master $ git push -u origin master
--set-upstream flag after push indicate that we want to make this repo the default repo when running both
git pull and
git push. Pull and push command always need the remote repo url and branch arguments in order to work. With set upstream, we set both git pull and git push to aim for origin master if there is no remote repo and branch arguments.
Now let's try a git pull command. In your local computer, create a new empty directory and initialize git repo.
$ mkdir pull-example $ cd pull-example/ $ git init
Add your remote repository by using
git remote add origin, then use
pull command. In my case:
$ git remote add origin https://github.com/nathansebhastian/pull-example.git $ git pull origin master
And the master branch will be downloaded into your local repo.