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.