Pushing

Once we are finished making changes locally, you have to push them on to the remote repository so that others can see them too. To do this we run

git push remote branch

Here branch is the remote branch to which we want to push to. If we omit it, then Git will assume you want to push to the main branch. remote refers to the remote repository to which you wish to push to. If omitted, Git will assume that you want to push onto origin.


If this is your first time pushing onto a remote, Git will ask for your GitHub credentials so that it can authenticate and make sure you have push access. We'll see how to store them next so that you don't have to supply them every time you push.


Sometimes, others will have pushed their changes before you. If so, Git will not let you push your changes until you update your local repository with the remote one. If this is the case, you just need to pull before you can push. Keep in mind that when pulling, you may encounter merge conflicts that you will have to resolve before being able to push.

Pushing 1

Some people online will tell you that when your changes get rejected, you should force push by running

git push -f

or

git push --force

You should NEVER EVER EVER EVER force push onto a remote repository unless you have discussed it with your teammates and everyone is in line with this action. What a force push does is it tells GitHub that it should discard all commits ahead of your local repository, and push your changes. So you are throwing away your teammates work.