0

I want to prevent my IDE (e.g. Visual Studio) to (unnecessarily) reload files when I do this, assuming I am on the master branch:

git checkout -b feature/myfeature
<do my changes, validate the result => great I want them back in the master-branch that HAS NOT CHANGED in the meanwhile>
git add -A; git commit -am 'my changes';
git checkout master
git merge feature/myfeature

How do I do this without a "checkout" of the master branch first before merging and causing files to change in the directory tree (in a fast-forward case like this one)?

David
  • 2,551
  • 3
  • 34
  • 62
  • You didn't make any commit to `feature/myfeature`, so it's the same as `master`. I have no idea what you're trying to do. – Jakub Matczak Jun 29 '17 at 10:26
  • directory tree will change when you checkout branch so visual studio will detect that.I think you can do a fast forward merge as discussed [here](https://stackoverflow.com/questions/3216360/merge-update-and-pull-git-branches-without-using-checkouts) – Rohith Jun 29 '17 at 10:35
  • @JakubMatczak added the commit for clarification – David Jun 30 '17 at 10:30

1 Answers1

0

So you start with

x --- x --- A <--(master)

You create a branch and do some work

x --- x --- A <--(master)
             \
              B <--(branch)

Now you want to fast-forward master. The simple (but arguably unsafe) method is to just force master to move

git branch -f master

If master really was at an ancestor of branch/HEAD then this will fast-forward it. If for some reason it wasn't at an ancestory of branch/HEAD it will still get moved. But as long as you haven't pulled in changes, it should be ok.

A safer solution is to check out master on a separate work tree to do the merge.

git worktree add path/to/new/worktree/root master
cd path/to/new/worktree/root
git merge branch
Mark Adelsberger
  • 42,148
  • 4
  • 35
  • 52