Adding an existing project to GitHub using the command line
-
Create a new repository on GitHub. In Terminal, change the current working directory to your local project.
-
Initialize the local directory as a Git repository.
git init -
Add a gitignore file thats specific to your project Find examples here: https://www.toptal.com/developers/gitignore
-
Add the files in your new local repository. This stages them for the first commit.
git add .orgit add --all -
Commit the files that you've staged in your local repository.
git commit -m 'First commit' -
Copy remote repository URL field from your GitHub repository, in the right sidebar, copy the remote repository URL.
-
In Terminal, add the URL for the remote repository where your local repostory will be pushed.
git remote add origin <remote repository URL> -
Confirm the configured remotes:
git remote -v -
Rename master to main
git branch -m master mainAlternative: Fix it once and be done with it:
git config --global init.defaultBranch mainbefore getting started -
Push the changes in your local repository to GitHub.
(override the remote)
git push -f origin main(don't override the remote)
git push origin main