Thomrl's Blog

Github - How to Push Files to a Repository in Terminal

I’m rusty with this, so there will be some uncertainties at the moment, but it pretty much includes all I did for mine to work.
I’ll come back to this.

When it has been setup

git add . To add all files in the directory to the next commit.
git commit -m "[title of commit]" . Create a commit.
git push -u origin main Push/Upload the commits in the queue.

Setting it up

Github Access Token

First of all you need a token which you can find in your Github settings under
Settings > Developer settings > Personal access tokens > Tokens (Classic).
Click Generate new token > (Classic). Give it the name and permissions you want it to have, it can also have everything.
It is recommended to have the token expire eventually for security reasons.

Setup your author identity

git config --global user.name "Your Name"
git config --global user.email "youremail@domain.com"
Self explanatory, but it doesn’t return anything which can make you uncertain if you did it correctly. You probably did.

Trial and error

I made a commit to begin with as you do with git commit -m "test" .

I saw a YouTube video and got this command to use:
git remote add origin https://[Access Token]@github.com/[Username]/[repository].git

Then used these commands
git branch -M main
git push -u origin main

The following command got me further after some error(s).
git push --set-upstream origin master

git push -u origin main I wasn’t able to use this.

git fetch I tried because I couldn’t push my commit.

git push -u -f origin main -f was needed for me because I kept getting rejections, and it didn’t help to pull, fetch or anything.

Useful commands

git status

#Github #Git #Terminal