Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git merge in the wrong direction?

Tags:

git

Git still confuses me from time to time!

I have a staging and a master branch. Usually development occurs on the staging branch, which gets merged into master periodically.

However some commits have been made directly to the master branch. This means that the updates are missing from the staging branch.

How to I bring my staging branch back up to date with the master? Am I right in thinking merges should always occur in one direction (i.e. staging > master) and the merging master > staging is not the way to go?

like image 376
Andy Harvey Avatar asked Jun 26 '13 09:06

Andy Harvey


People also ask

Can git merge be reversed?

You can undo a Git merge using the git reset –merge command. This command changes all files that are different between your current repository and a particular commit. There is no “git undo merge” command but the git reset command works well to undo a merge.

How do you reverse a merge conflict?

On the command line, a simple "git merge --abort" will do this for you. In case you've made a mistake while resolving a conflict and realize this only after completing the merge, you can still easily undo it: just roll back to the commit before the merge happened with "git reset --hard " and start over again.


1 Answers

I think it is a perfectly reasonable process to merge master into staging every now and then. This brings staging up to date with the latest patches in master.

You can keep developing on staging after that, occasionally bringing it up to date again with a merge.

When staging has reached a stable state, you merge it to master.

Merging between branches does not have to be unidirectional, nor does it have to be a one-time deal.

(The above is, of course, not the only possible branching strategy. See this for an example of a more advanced model)

like image 66
Klas Mellbourn Avatar answered Oct 28 '22 14:10

Klas Mellbourn