1

Using SourceTree, I reset my local repository to a previous commit. I then used GitBash to do a gitk --date-order to see the commits in the Bare repository which I push to in order to update that to the same previous commit. I did this using git update-ref HEAD [SHA ID]. Both the Bare repository and the one I originally reset have only one branch.

Now I want to update my remote repository back to that previous commit. I am unclear on how to use the git remote commands to do the exact same thing. The wrinkle being that I have two remote branches: development and master. I only pushed those changes I wanted to reset to the development branch (master has not been merged yet).

Can anyone show me the commands to update my remote development branch correctly?

REMESQ
  • 1,080
  • 2
  • 26
  • 58
  • 1
    You want to know how to update a remote branch to be the same as your local branch? – Bryce Drew Jun 22 '16 at 17:41
  • 1
    Force push your localbranch to your remote. `git push $development $localbranch:$remotebranch -f` – Bryce Drew Jun 22 '16 at 17:42
  • @BryceDrew, will this effectively delete the commits I want to get rid of? And if so do I replace "$development $localbranch:$remotebrach" with the names of my branches? So it looks like `git push $development $development:$development`? – REMESQ Jun 22 '16 at 18:10
  • 1
    Yes, but don't do that if you want to keep your co-workers from strangling you. Don't do this normally. If someone is working on their code on top of that history, your new branch won't be compatible with their code. Read [This](http://stackoverflow.com/a/6204804/6194839), [This](http://stackoverflow.com/a/6206542/6194839), and [This](https://www.atlassian.com/git/tutorials/merging-vs-rebasing/). You don't want to mess with remote history. Just add a new commit to undo a previous commit's history. – Bryce Drew Jun 22 '16 at 18:17
  • 1
    Those are variables I used because I don't know your branch names, or the location of your remote servers. For me, it could be `git push ~/Desktop/foo foo:master -f`, for you it could be something else. – Bryce Drew Jun 22 '16 at 18:20
  • 1
    @BryceDrew This is a personal repository and not shared with anyone, so no worries there. Sorry to be a bit daft, but I am new to git and I obviously don't know the commands well enough. My local repository is in E:/Code/Code.Website1. The local branch is "development". The remote repository's branch is also "development". So would it be: `git push ~/Code/Code.Website1/development development:development -f`? – REMESQ Jun 22 '16 at 18:28
  • 1
    `git remote add development E:Code/Code.Website1` then `git push development -f` Understand that if you have not backed up the development remote, the history will not be preserved, and you won't be able to get that back. – Bryce Drew Jun 22 '16 at 18:44
  • 1
    @BryceDrew That worked. Thanks so much. I'll mark as answer if you want. – REMESQ Jun 22 '16 at 18:45

1 Answers1

1
git remote add development E:Code/Code.Website1
git push development -f

Understand that if you have not backed up the development remote, the history will not be preserved, and you won't be able to get that back.

Understand that you should not be changing your remote history if your remote is accessible by anyone else.

Bryce Drew
  • 3,527
  • 1
  • 11
  • 24