Pushing local repo to remote in git

We have already seen how to initialize a local repository using Git. Now suppose you want to push this repository to remote repository on GitHub. Below image shows how to add remote repository and push local repository to remote one. In 2 steps, you can push the changes.
  • First register remote repository using git remote add origin repository_url
  • Then push the local repository changes to remote using git push -u origin master command. The meaning of this command is that push the local repository’s current branch to the master branch of remote repository. -u switch sets the upstream branch permanently. So next time, you can just use git push command
Note that by default remote repository is called as origin. But you can rename it using below command.
git remote rename origin myorigin

Here is the output of above example.

Complex problems, Simple Solutions