-1

I am working on a project where I use the master branch to only contain the various "release" worthy states (following the model here: https://nvie.com/posts/a-successful-git-branching-model/).

I have created a new branch for the last changes before the new release version, which includes unstaging some obsolete files (using git rm --cached file1 file2 on the local release-branch). So at the current state, my local master branch is still tracking file1 and file2, while the local release branch is not.

How can I now merge the release branch into the local master, such that the local master adopts the unstaging (i.e. is no longer tracking the two files)? When I try to change to the master branch for the merge command, I get ">error: The following untracked working tree files would be overwritten by checkout".

To be clear, I do want to keep the files in my local directory. I just want Git to stop tracking them, so that when I push my local master to my remote, the files will be removed from the remote.

1 Answers1

0

To merge anything into master, you must check it out. But checking out master means syncing your worktree to the state of master, which means those two files must be overwritten to their current state in master. There are ways to "checkout" a branch without changing your local worktree, but you can't do those if you want to do a merge.

Solution:

  1. git stash -u to stash away the untracked files
  2. do your merge.
  3. git stash pop to get them back.
Inigo
  • 12,186
  • 5
  • 41
  • 70