#Adding an existing project to GitHub using the command line
Simple steps to add existing project to Github.
In Terminal, change the current working directory to your local project.
##2. Initialize the local directory as a Git repository.
git init
Add the files in your new local repository. This stages them for the first commit.
git add .
or:
git 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>
Sets the new remote:
git remote -v
Push the changes in your local repository to GitHub.
git push origin master
Pushes the changes in your local repository up to the remote repository you specified as the origin
This might happen if you create a new github repo with a readme file. It could also be totally different code and somehow you feel confident to merge. Then you can do a fetch of the github repo:
Followed by a merge with --allow-unrelated-histories:
When the commit file opens just save it or update it.
Then you are ready for the push
This will sync your local repo with your remote repo (origin on branch main).
Here I used main because github is now using main by default instead of master.
If locally your HEAD is on master then you can rename the branch so: