How to Make the Current Git Branch a Master Branch

In this snippet, we will go through an example of making your current git branch to a master branch. For meeting this goal, the git checkout command, as well as the git merge command, should be run. Here is what you need to run:

git checkout better_branch
git merge --strategy=ours master # keep the branch content, but record a merge
git checkout master
git merge better_branch # full speed the master up to the merge

In case you want to make your history clearer, it is recommended to add some information to the merge commit message. You should change your second line to:

git merge --strategy=ours --no-commit master 
git commit # adding information to the message of the template merge

Defining the git branch Command

The git branch command is a go-to command for managing all the aspects of your branches. No matter it's in the local git repository or the remote. Generally, git branch helps you create, list, or delete branches.

Each new branch is created for encapsulating the changes when you wish to add new features or fix current bugs. It makes your history clearer before merging it. Branches can be described as an isolated line of development. They represent a way of requesting a new working directory, staging area, and project history.

Any time you create a new branch, Git will make a new pointer. It doesn’t change your repository’s history.

Description of Git Merge

The git merge command is used for integrating independent lines of development to a single branch. It works along with the git checkout command for selecting the current branch and the git branch command with the -d option for deleting the obsolete target branch.

Primarily, the git branch command is used for combining two branches. You can also use it for merging multiple commits in one history.

Definition of the git checkout Command

This command is primarily used for navigating between the created branches. When you run the git checkout command it updates the files in your working directory to correspond with the version that is stored in the given branch. It also orders Git to record new the overall new commits on that branch.

Git checkout should not be confused with the git clone command. The latter works to fetch code from a remote repository.


Do you find this helpful?

Related articles