Abel Callejo
Abel Callejo

Reputation: 14929

How to make a branch as master w/o using git merge?

Branches

Current setup

+-master-+-master--+-master--+
         +-staging-+-staging-+-staging-+-staging-+

Make staging as master

What I want to do now is to make staging as the master without using git merge because I am no longer able to keep track of the changes and the position of the heads.

Current branch is staging and I wanted to achieve this

+-master-+-master--+-master--+                   +-master-+
         +-staging-+-staging-+-staging-+-staging-+

Can the master be overridden by staging using these steps?

  1. git checkout master
  2. change something
  3. git add *
  4. git commit -m "override the master version"
  5. git push -u origin master

Upvotes: 1

Views: 2480

Answers (2)

Ashwin Patil
Ashwin Patil

Reputation: 44

I would suggest doing something like this:

git checkout staging
# keep the content of this branch, but record a merge
git merge --strategy = ours master   
git checkout master
git merge staging             # fast-forward master up to the merge

If you want your history to be a little clearer, I'd recommend adding some information to the merge commit message to make it clear what you've done. Change the second line to:

git merge --strategy=ours --no-commit master
git commit          # add information to the template merge message

Upvotes: 1

Paul
Paul

Reputation: 13238

If I understood your question correctly, you can do

git checkout master
git reset --hard staging

This will make master point to the same commit as staging. If your master has any commits that are not in staging you will lose them.

Upvotes: 5

Related Questions