1

I have a scenario where there is a master branch, and a feature branch is cut from the master branch.

  1. Master branch
  2. Feature branch

all our custom changes to the code are committed to the feature branch for custom configs testing. Meanwhile there will be many commits happening to the Master branch in parallel by other developers.

So after a week or two the I want to get all the new changes from the master branch and git rid of all the commits I made in the Feature branch. i,e want to get my feature branch in sync with latest master without my commits.

I got solution to get the master commits to my feature branch but not very clear solution to get rid of my commits from my feature branch.

My end goal is to sync my feature branch every couple of weeks with master branch and remove all my commits as well, so my feature branch is same as the master.

This can be done simply by deleting the feature branch and creating a new one from master, but we do not have the power to create/delete new branch, so we need to live with a single feature branch for all our custom testing.

Karthic.K
  • 416
  • 5
  • 15

1 Answers1

2

we do not have the power to create/delete new branch

If you can force push, though, there is the simple option of resetting your feature branch:

git switch master
git pull
git switch -C feature master
git push --force

If not, pick one option from "git command for making one branch like another".

For instance:

git switch -c tmp master
git merge -s ours feature       # ignoring all changes from feature
git checkout feature
git merge tmp                   # fast-forward to tmp HEAD
git branch -D tmp               # deleting tmp
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250