Git is the versioning control system that tracks the development project changes to the local machine and then pushes them to the centralized server for updating other project members. They can create new branches to make changes locally. Moreover, developers can change the current working branch to another branch.
This post will discuss about making the current working Git local branch a master branch.
How to Make the Current Working Git Branch a master Branch?
Check out the below-given steps to change the current working Git branch into a master branch:
-
- Navigate to the Git root directory.
- List the current local branches.
- Select the branch which needs to change into the “master” branch and switch to it.
- Use the “git merge –strategy=ours master” command.
- Switch to the “master” branch and merge it with the target branch.
Step 1: Redirect to Root Directory
At first, execute the “cd” command and navigate to the provided path:
Step 2: Display Existing Branches
Next, check the list of all local branches by running the “git branch” command:
From the below-provided output, we have selected the “alpha” branch for further process:
Step 3: Switch to “alpha”
Now, type out the “git checkout” command and move to the specified branch:
Step 4: Merge “master” Into Current Branch
After that, run the provided command to merge the “master” branch with the current working branch:
Here, the “–strategy=our” is the merging strategy. After executing the above-stated command, the “MERGE_MGS” file will open. Now, add a commit message, save changes, and close the file:
After that, the merge operation is performed successfully:
Step 5: Checkout to “master”
Next, switch to the “master” branch by typing out the “git checkout” command:
Step 6: Fast-Forward Merge
Finally, execute the “git merge” command to perform the fast-forward merge on the current working branch:
It can be observed that the commit of the “master” branch is successfully merged with the “alpha” log history:
Step 7: Verify Merge Operation
Lastly, utilize the “git log” command to verify the merging operation:
As you can see, the HEAD is pointing to the “master” and “alpha” branches, which indicates that the “alpha” branch is changed into the “master”:
That’s all! We have explained the process of making a current working Git branch a master Branch.
Conclusion
To change the current working Git branch into a master branch, first, move to the Git root directory and list the current local branches. Then, select the target branch which needs to change into the “master” branch and switch to it. Next, execute the “git merge –strategy=ours master” command. Lastly, navigate to the “master” branch and run the “git merge <target-branch>” command. This post described the method of making the current working Git branch a master branch.