If on a local branch, how should I push that repo to remote from local repo that already exists?

I am pretty new to programing/git and am trying to learn best practice.
If I have a repo I created on my computer, what is the best way to make that a repo on github.

I have been creating on github for the most part and would like to know what the practice would be if I wanted/needed to do it in reverse.


  • Can I hide a branch in a git repo for all remote clones?
  • How to remove a file from git repo on local and remote
  • How to pass in git rsa passphrase from remote ssh?
  • git operations on remote repository without local clone
  • Jenkins + PowerShell Calling a Specific Branch in Git
  • Checkout GIT repository through Internet
  • Creating a git repo on a remote server from a local machine
  • Is there a way to force a commiter enter their username in git bash
  • 2 Solutions collect form web for “If on a local branch, how should I push that repo to remote from local repo that already exists?”

    You need to create repository on GitHub first. To avoid confusion create it with the same name you already have to your repository.

    Change the current working directory

    cd project_folder

    Assuming you have initialized your repository and committed some files using:

    git init
    git add .
    git commit -m "First commit"

    Copy the newly created repository URL and add remote using this command:

    git remote add origin remote_repository_URL

    push to remote repository

    git push origin master 
    # master here is your branch 

    Follow this link for detailed steps

    Remember that before pushing your repository to GitHub you need to commit your changes:

    git commit -m "My last changes"

    Then you need to create empty project on GitHub without readme nor gitignore file.

    To send your code to github you shall add remote(which is your empty github project) to your local repository:

    git remote add origin <github project url>

    At last you should push your state of repository to remote:

    git push origin master
    Git Baby is a git and github fan, let's start git clone.