How to push an existing project to GitHub?
Sometimes I want to push a project to GitHub. But often when I do that my project is somehow nested in some folders on GitHub instead of having the root of my project there. That's why I decided to figure out how to make sure that won't happen anymore and how I'll always be able to push a fresh project to GitHub.
Create a new empty repository on GitHub and don't thick any boxes that will already add files to your repository.
Go to the project on your file system and add a
.gitignorefile to the root of your project. On GitHub you can find some useful templates for
Open a terminal.
Run the following command in the terminal to create a new Git repository.
To stage all files of your project before committing run the following command.
git add .
To commit all staged files run the following command after replace
WRITE YOUR OWN MESSAGEwith your own commit message.
git commit -m "WRITE YOUR OWN MESSAGE"
Run the following command to rename the local branch from
main. We have to do this because the default master branch on GitHub is called
main, but the default branch created with the
git initcommand is called
git branch --move main
OR you could also use a shortcut with the following command.
git branch -M main
Copy the remote URL of your repository on GitHub.
Run the following command to add a remote to the repository so git knows to what remote you want to push your files. Replace the example remote URL with your own URL.
git remote add origin https://github.com/IkBenDeSjaak/EXAMPLE.git
To finally push your files to your repository use the following command.
git push -u origin main