How to branch and merge using Git Bash

Home > Search > How-to
  by

Branches can be used to create separate containers for certain files. For example, let's say the master branch is the production ready files, and each child branch are staging files. In this example, staging files can be put in MyBranch, and the MyBranch can be merge into the master branch when the staging files are ready for production.

 

Use the git branch branch_name command to create a new branch. In this example, a new branch named myBranch is created.

$ git branch myBranch

 

Use the git checkout branch_name command to use a branch. In this example, myBranch is checked out.

$ git checkout myBranch

 

Let's create a new file named branch.txt in MyBranch. Stage and commit branch.txt. There is now a file named branch.txt at C:\Users\john.doe\Sample.

 

Use the git checkout master command to return to the master branch.

$ git checkout master

 

Branch.txt is no longer listed at C:\Users\john.doe\Sample.

 

While in the destination brach, use the git merge branch_name command to merge files from another branch into the destination branch. In this example, we want to merge MyBranch into master. Ensure you are in the master branch.

$ git checkout master
Switched to branch 'master'

$ git status
On master branch
. . .

 

Use the git merge branch_name command to merge the files from MyBranch to master.

$ git merge MyBranch

 

Now, branch.txt is in the master branch.



Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.




Please enter in the box below so that we can be sure you are a human.




Comments