Once again I am writing a PSA to myself on pushing code to a remote git repository after having started writing code.
I did this before on the previous, and equally pointless, version of this website.
Anyway, you’ve written your code and have done too much faffing about with it to start over with a brand new repository, so you’ve instead created a repo on GitHub and want to push your local code up to it.
-
Copy the HTTPS clone link
-
Initialise your local repository as a git repository with:
git init
-
Add your files to the local repo:
git add .
-
Commit all your files:
git commit -m "Initial commit"
-
Rename your branch if it differs from the remote repo (i.e main vs master)
git branch -M main
-
If your remote repo is not empty (maybe you initialised it with a readme or gitignore file?), pull the repo down:
git pull origin main --allow-unrelated-histories
-
Push your files up:
git push -u origin main
-
Forget all this information in 30 minutes time and google it again the next time you make this mistake
And there you have it, try to remember this time, dumbass.
3rd February 2025