Github – Create a repository from existing directory
- enter terminal of the directory, run:
git init -b main
The message will be like:
Initialized empty Git repository in your path/.git/
- stage all the files in the project:
git add .
- commit all the files in the project:
git commit -m "First commit"
-
create a repository from github web console with your github account
-
add the url of the remote repository you just created to the lcoal repository
git remote add origin <REMOTE_URL>
Verifies the new remote URL
git remote -v
git push origin main
you may receive the eroor like:
Updates were rejected because the remote contains work that you do not have locally
In this case, that is because when we are trying to push to remote repository but has created a new file on remote which has not been pulled yet
One solution is to use force push:
git push -f origin main
But this is really dangerous, because it will overwrite the history that is in remote to keep the remote history like your local copy.
A more safe solution will be:
- Pull from the remote to keep you local repository updated
git pull origin main
- Then push the local repository remotely
git push origin main
Comments are closed.