Adding a local git repository to GitHub
If you are like me you often begin a new a new project on your local machine. Perhaps this is because it is a quick test project just for a proof of concept. Perhaps it is a project that you have been working on for some time and you have finally decided to push it to GitHub.
If you did not create the repository on GitHub originally you will first need to create a new repository on GitHub so that your project has a place to go. You can do this by following the instructions in the GitHub Docs on how to Create a new repository.
On the Create a new repository page be sure to select the correct Owner if you belong to one or more than one organization(s).
Enter the name of the repository to be created on GitHub into the Repository name field. Be sure this is the same name as your local repository name. This will help avoid confusion in the future.
Enter an optional description and then select the visibility of the project. If you do not want the project to be visible to anyone that happens upon it be sure to choose Private.
The last optional step is to initialize the repository with a README, .gitignore or license. Since you will be importing an existing local repository do not initialize your repository with any of these items. Click the "Create repository" button to initialize the repository.
After the repository is initialized you will be given a repo URL. You will need this url in the future so be sure to take note of it.
If you have not yet created a local repository then you do this now. Before pushing your local repository to GitHub you should create a README.md and .gitignore file at a minimum if you have not already done so.
git init -b main git add README.md git commit -m "Initial commit"
With at least a README.md file and a .gitignore file you can now connect the local repository to the remote repository on GitHub. To do this you will use the
git remote command. You will need the repository URL that was created for your GitHub repository.
git remote add origin <GitHub Repo URL> git push -u origin main
Your local repository is now pushed to GitHub. You can now use your normal git commands to keep the local and remote repository up to date.
You must be logged in to see the comments. Log in now!