Maaz Patel
Maaz Patel

Reputation: 774

git remove file while mereging

I am using bit bucket for version controlling.I have repository x,which contains two branches 1) master and 2) sub_branch.

I want to delete some file from master branch while merging sub_branch into master branch.

Though I have found the way to delete file : How can I delete a file from git repo?

I have tried with following command:

git checkout master
git rm <my_file>
git commit -m 'delete file'
git merge sub_branch

unfortunately this dosen't work.

My question is I want to delete some file from a branch before I merge other branch with it.

Thanks a lot. please put your comments if you didn't get anything.

Upvotes: 0

Views: 150

Answers (2)

Sajib Khan
Sajib Khan

Reputation: 24136

You need to Add (Stage deleted files) the changes before Commit.

$ git checkout master
$ git rm <my_file>

$ git add -A  # staged deleted, modified & new files

$ git commit -m 'delete file'
$ git merge sub_branch

Additional: if conflict happens then Accept the master (ours) changes.

$ git checkout --ours -- .
$ git add -A
$ git commit -m 'Fix conflicts'  

Upvotes: 1

hspandher
hspandher

Reputation: 16733

Just remove the file, commit the change and merge the other branch.

git checkout master
git rm <my_file>
git commit -am 'delete file'
git merge sub_branch

Upvotes: 1

Related Questions