iBelieve
iBelieve

Reputation: 1544

How do I push corrected commits to a remote repository?

I realized I had set my user.name up wrong, so I used this answer to fix the incorrect commits. Locally, it worked great. However, git now tells me

$ git status
# On branch master
# Your branch and 'origin/master' have diverged,
# and have 15 and 15 different commits each, respectively.
#   (use "git pull" to merge the remote branch into yours)
#
nothing to commit, working directory clean

So, now I need to somehow send my changes to my GitHub repository, but when I push:

$ git push
WARNING: gnome-keyring:: couldn't connect to: /run/user/mspencer/keyring-uscL41/pkcs11: No such file or directory
Username for 'https://github.com': iBeliever
Password for 'https://[email protected]': 
To https://github.com/iBeliever/weather-desktop.git
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'https://github.com/iBeliever/weather-desktop.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Merge the remote changes (e.g. 'git pull')
hint: before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

I'm not quite sure how to fix this. I've dealt with remote changes before, and solved them by pulling and merging, but I'm not sure what to do in this case. I need to update my GitHub repository with the corrected names, how do I do that?

Upvotes: 2

Views: 373

Answers (2)

atreat
atreat

Reputation: 4413

Steven's answer is correct but very dangerous. So be careful when you use a forced push.

First of all, git push -f will force push all local branches to the remote repository.

To just push the master branch, you must specify it.

git push -f origin master

When doing this you will want to tell all the other people that have access to this repository to pull down your changes before they make any additional commits. Otherwise the branches will diverge in crazy ways that you don't want to deal with.

Upvotes: 5

Zombo
Zombo

Reputation: 1

You can force the push

git push -f

More info

      -f, --force
          Usually, the command refuses to update a remote ref that is not an
          ancestor of the local ref used to overwrite it. This flag disables
          the check. This can cause the remote repository to lose commits;
          use it with care.

Upvotes: 1

Related Questions