I can’t believe that every 3 months, I forget how to do this.
Here’s how to make the git push
command work for pushing an existing folder/repository from the command line:
Step-by-step process:
- Ensure you have initialized your local repository:
git init
- Add the remote repository:
git remote add origin <url_of_remote_repository>
- Here you must recall that it
<url_of_remote_repository>
is typically in following format:https://<PERSONAL_ACCESS_TOKEN>@github.com/<username>/<username>.github.io.git
- You can get a classic token from developer’s settings in your github page. Tick all the necessary permission boxes. I typically copy paste this code in secure location for future use.
- Add files, commit and push
git add .
git commit -m "Initial Commit"
git remote -v
git push origin master
How to reset token
- If you already had done the above part but now the token has expired.
- Open terminal in vscode, if you are using vscode to commit and push code.
- Check if all the information is correct by using this command
git config --list
- Most likely, the token is wrong. So you can set it up again using
git remote set-url origin https://<PERSONAL_ACCESS_TOKEN>@github.com/<username>/<repo>.git