1

When I want to push changes into my remote acceptance environment, I want to make my test branch identical to master in git before merging in the files from the new dev branch.

What is the easiest way to make the "test" branch a snapshot of master and merge in changes from a new branch?

Tim Thomas
  • 11
  • 1

3 Answers3

0

If your changes are in test and you want to update your local master, just checkout master and then do git merge test.

Christoph
  • 6,841
  • 4
  • 37
  • 89
  • Actually, the changes are in newbranch. What I am looking to do is update test to be exactly like master and merge the changes from newbranch into test. I have tried to do that using many techniques and I can't get it to work. – Tim Thomas Aug 30 '16 at 18:15
  • Could you explain what exactly you tried? What is the relation of the branches? – Christoph Aug 31 '16 at 06:20
  • For the first part, getting test to be a copy of master, I did this: `git fetch --all` `git reset --hard origin/master` `git reset --soft origin/test` `git add` `git commit -m "blah"` `git push`. For the second part of merging in the changes, I did `git checkout test` `git merge newbranch` and it said "Already up-to-date", but if I do `git diff --name-status test..newbranch --` it shows all of the changes I want merged in! – Tim Thomas Aug 31 '16 at 13:04
  • I have to think, about your process. Anyways, please read [that](http://stackoverflow.com/questions/8358035/whats-the-difference-between-git-revert-checkout-and-reset). I am not sure yet, but I think the `reset` part explains what you see(?). – Christoph Aug 31 '16 at 13:24
0

If the current (or old) commit test is at is not important to you (or anyone else).

You can simply do

$ git checkout test
$ git reset --hard master
$ # In case your local master is not up-to-date use origin/master

This will move the pointer of test to the current commit master is pointing at.

AnimiVulpis
  • 2,670
  • 1
  • 19
  • 27
  • I did do something similar, and more... For the first part, getting test to be a copy of master, I did this: `git fetch --all` `git reset --hard origin/master` `git reset --soft origin/test` `git add` `git commit -m "blah"` `git push`. For the second part of merging in the changes, I did `git checkout test` `git merge newbranch` and it said "Already up-to-date", but if I do `git diff --name-status test..newbranch --` it shows all of the changes I want merged in! – Tim Thomas Aug 31 '16 at 13:09
  • 1
    I think `git reset` is a really dangerous command as it really deletes stuff. I try to avoid this command in most cases: I only use it on a file-basis where I am really sure that I want to delete the changes. – Christoph Aug 31 '16 at 13:19
  • You stated "I want to make my test branch identical to master". Which I assumed implies throwing away changes made in `test`. – AnimiVulpis Aug 31 '16 at 13:46
  • @Tim Thomas: Is the above interpretation from @AnimiVulpis correct? You want to delete work to obtain another status? As discussed above, `reset` deletes work and I think that causes your result. Why do you have to `reset` at all? (What is your idea?) – Christoph Aug 31 '16 at 16:19
  • yes, effectively I want to destroy test and start with a copy of master when I do this before I merge in newbranch. I actually tried that - I deleted the test branch and made a new branch from master, but that didn't work either - it says Already up-to-date" when I do `git merge newbranch`, but if I do a diff `git diff --name-status test..newbranch --` it shows that there ARE differences, but it won't recognize them when doing `git merge newbranch` – Tim Thomas Aug 31 '16 at 20:53
  • This should only happen **If all named commits are already ancestors of HEAD, git merge will exit early with the message "Already up-to-date."** as stated in [git-merge pre-merge checks](https://git-scm.com/docs/git-merge#_pre_merge_checks). So the differences have to be from changes done to the `master` branch after `newbranch` was merged. If this is not the case we have to find out what is wrong there. – AnimiVulpis Aug 31 '16 at 22:19
  • Not sure what happened here. I ended up having to clone the repo again somewhere else, checkout newbranch and rsync the added, changed and deleted files to the test folder in the original clone. – Tim Thomas Sep 01 '16 at 03:30
0
git fetch && git rebase origin/master && git push origin <your-branch> -f
Wade Williams
  • 3,943
  • 1
  • 26
  • 35