Adding files to Github with push

Posted under » Version Control on 24 April 2021

As usual you start by making a local GIT repo. Then, go go to GITHUB and create a new repo, for example rubber.git. Set to private access if you like it that way.

Then add remote.

$ git remote add origin git@github.com:anoneh/rubber.git

It doesn't matter if you are trying to work on a branch or main, you still have to connect to the main.

Confirm connection by

$ git remote -v

Define what branch this is. In this case main. Then push the comitted files.

If the branch is not existing, best or easier to create the branch from GITHUB.

$ git branch -M main
$ git push -u origin main

This will create a brach called main. Then you ask for a pull request to merge with main.

The opposite is Git pull where you should start with.

Before you commit, you have to pull first. After which you can push to the main or branch that you fetched from.

Git push is something like update in SVN but update in SVN is both push and pull.

Best practice is to pull first before you commit and push. If you are prevented from pushing, then use force.

Sometimes you get a "git error: failed to push some refs to remote". It's time you use some brute push.

$ git push -u origin main --force
$ git push -f origin master

Sometimes you misspelled while adding remote so you get an error... Git push: “fatal 'origin' does not appear to be a git repository - fatal Could not read from remote repository.”

Remove the old remote by

$ git remote remove origin

Redo the process until you are able to push.

web security linux ubuntu python django git Raspberry apache mysql php drupal cake javascript css AWS data