0

I've been having some problems with my remote (origin) QA branch. I think it is time to override it with origin master.

I am thinking about doing the steps below:

1.git checkout master
2.git push origin master:qa --force

Will it work ?

Should I do the following before ?

1.git checkout qa
2.git branch -D qa 

Thanks in advance.

1 Answers1

2

A branch is a just a pointer to a commit. You could just delete the remote qa branch and recreate it off master.

$ git checkout master
$ git push origin --delete qa 
$ git branch -D qa
$ git checkout -b qa
$ git push -u origin qa
GoodDeeds
  • 5,837
  • 4
  • 28
  • 51
  • Thanks. What actually does $ git push origin --delete qa (after $ git checkout master) ? It pushes local master to origin (remote) qa, while deleting the original content at origin qa ? Should not the last line be git pull origin qa ? – Bruno Toledo Jan 24 '20 at 22:27
  • @BrunoToledo It deletes the remote qa branch. And the last line is to push the new branch information itself to the remote (and create the remote qa branch), not any actual commit. – GoodDeeds Jan 24 '20 at 22:29
  • @BrunoToledo You could have the git checkout master as the third step too. But the deletion of qa would require you to be on another branch, so I put is as the first step. – GoodDeeds Jan 24 '20 at 22:30
  • @BrunoToledo Because you want your qa branch to be in sync with master. I just realized that I assumed your local and remote master are in sync though, if that is not the case you need to checkout to the appropriate commit you want to branch off of. – GoodDeeds Jan 24 '20 at 22:36
  • Ok. Now what I do not understand is what I will be pushing to origin qa at tha last step if it will just be created at "git checkout -b qa". – Bruno Toledo Jan 24 '20 at 22:39
  • @BrunoToledo Sorry, I missed a u flag. It is to create the qa branch in remote as well. You can see https://stackoverflow.com/q/2765421/5987698 – GoodDeeds Jan 24 '20 at 22:45
  • where in those lines I send local master code to origin qa ? – Bruno Toledo Jan 25 '20 at 01:46
  • @BrunoToledo Since you just want origin qa to be at the same position as origin master, there is no need to send any code. The commits are already there in the remote. – GoodDeeds Jan 25 '20 at 11:52
  • But after doing $ git push origin --delete qa, origin qa will be empty, rigth ? I mean no code at all. – Bruno Toledo Jan 25 '20 at 13:35
  • I think, I got it ! Once commits are cleaned the from qa, the line push -u origin qa will "send" no commits, which means qa will reflect master. One last doubt. Should I pull origin master to local master before, as it is a collaborative project and currently local master is behind origin master ? Thank you very much for the patience. As you can see I am a beginer in git. – Bruno Toledo Jan 27 '20 at 12:25