3

I usually work on my Master branch, and push to Production. I accidentally worked on Production branched and deployed the app. Now my Production has the latest version, Master has older version.

What should I do to update the Master branch files to the same as Production? What commands to issue?

I will be careful and work only on Master branch in future. Thanks.

Victor
  • 13,010
  • 18
  • 83
  • 146

2 Answers2

3

Make your current branch master and run

git merge production

or

git rebase production

See merge vs rebase for differences.

Community
  • 1
  • 1
Chandra Patni
  • 17,347
  • 10
  • 55
  • 65
  • That second example is not correct. Rebase works the "other way around" from a merge. You'd want to switch to the production branch and run `git rebase master`. In any case, rebasing is not advised in this case since he wants the same commits on both branches (and has likely pushed the production branch to a remote already). A merge is more appropriate here. – Jimmy Nov 20 '10 at 09:34
  • If I run, `git rebase master` on production branch, I get "Current branch production is up to date." When I run , `git rebase production` on master, it does fast-forward. "First, rewinding head to replay your work on top of it... Fast-forwarded master to production." – Chandra Patni Nov 20 '10 at 09:42
  • I used the first example, now it's the same. But when I run `git status`, it says `Your branch is ahead of 'origin/master' by 5 commits.`. How do I fix this? – Victor Nov 20 '10 at 11:15
  • @Victor - That is telling you that your local branch has changes that have not been pushed to the remote branch. Read more about remotes and branches: http://progit.org/ – Jimmy Nov 20 '10 at 17:25
  • That makes sense if your master branch is ahead of your production branch. In this case, the opposite is true. He's accidentally made changes to production that were supposed to be made to the master first. – Jimmy Nov 20 '10 at 17:26
1

If it hasn't been pulled to a remote or the remote can be overwritten, I would cherry-pick the new commits from production to master, delete the commits from production (via interactive rebase) and then do the usual rebase-merge cycle for updating production branch from master.

Check progit.org for each steps exact syntax and be careful, git is very powerful, so you can fix any screw up, but you can also screw it pretty bad.

miguelbernadi
  • 172
  • 2
  • 11