Git

How to Reset Develop Branch to Master

While working on large development projects, users make multiple modifications and changes to the project source code files, which becomes messy. Sometimes it is required to delete or reset the data of the Git branches to free up space, or you may need to make a copy of another existing Git branch. For this purpose, the “git merge –no-commit <branch-name>” command is used to merge, commit, and override the added changes. Then, set the “git checkout –theirs master .” command for resetting develop branch.

This guide discusses the method of resetting the develop branch to the master branch.

How to Perform Reset Operation on Develop Branch to Master?

Follow the provided procedure to reset the develop branch into the master branch:

  • Go to the Git repository.
  • Show the local branches list.
  • Switch to the “develop” branch.
  • Merge, commit and override the added changes by running the “git merge –no-commit master” command.
  • Execute the “git checkout –theirs master .” command for checking out from develop to the master branch that contains the new rebased commits.
  • Verify the resetting operation through Git log history.

Step 1: Switch to Root Directory

At first, execute the “cd” command and move to the specified repository path:

$ cd "C:\Users\nazma\Git"

Step 2: Show List of Branches

Use the “git branch” command to list all existing local branches:

$ git branch

From the below-given list, we have selected the “develop” branch:

Step 3: Move to “develop” Branch

Now, switch to the target “develop” branch with the help of the following command:

$ git checkout develop

Step 4: Merge and Commit Changes

To merge and commit the added changes, the below-stated command can be used:

$ git merge --no-commit master

In the above-stated command, the “–no-commit” option is used to override the added results:

Step 5: Switch to “master” Branch

After that, switch to the “master” branch through the provided command:

$ git checkout --theirs master .

Here, the “–their” flag refers to the target branch that contains the new commits which are rebased:

Step 6: Verify Reset Operation of “develop” Branch to “master”

Lastly, ensure whether the develop branch is reset to the master by running the “git log .” command:

$ git log .

According to the below-given output, the develop branch is reset to the desired branch successfully:

We have efficiently provided the process of resetting the develop branch to the master branch.

Conclusion

To reset the develop branch into the master branch, first, go to the Git repository and check the list of all local branches. Then, switch to the “develop” branch, run the “git merge –no-commit master” command to merge, commit and override the added changes. Next, to contain the new commit to master, which is rebased in the develop branch, execute the “git checkout –theirs master .” command. This guide illustrated the process of resetting the develop branch to the master branch.

About the author

Maria Naz

I hold a master's degree in computer science. I am passionate about my work, exploring new technologies, learning programming languages, and I love to share my knowledge with the world.