Git Branch

Please generate a root-commit to proceed with Git branches.

  1. Create branch

    (master) $ git branch {branch_name}
  2. Switch branch

    (master) $ git checkout {branch_name}
  3. Create and switch branch

    (master) $ git checkout -b {branch_name}
  4. Delete branch

    (master) $ git branch -d {branch_name}
  5. List branches

    (master) $ git branch
  6. Merge branch

    (master) $ git merge {branch_name}
  • Merge {branch_name} from master branch

2. branch merge scenarios

Branch-related commands are simple.

You should be able to understand what situation you're in and use them freely in various scenarios.

Scenario 1. fast-forward

Fast-forward is a situation where there are no changes to the master branch after the feature branch is created

  1. Create and switch to feature/crud branch

    • or

  2. Commit after completing work

    • Create arbitrary files and commit

    • add, commit

  3. Switch to master

  4. Merge to master

  5. Result -> fast-forward

  6. Delete branch


Scenario 2. merge commit

In the process of merging different histories (commits), different files are modified

Git performs auto merging and a commit occurs.

  1. Create and switch to feature/signout branch

  2. Commit after completing work

  3. Switch to master

  4. Generate additional commits on master!!

    • Please modify or create different files!

  5. Merge to master

  6. Result -> merge commit automatically occurs

  7. Check graph

  8. Delete branch


Scenario 3. merge commit conflict

In the process of merging different histories (commits), the same part of the same file is modified

Git cannot perform auto merging and shows a conflict message.

It marks the location in the file according to standard format.

You must manually fix it to the desired form of code and manually create a commit.

  1. Create and switch to feature/signup branch

  2. Commit after completing work

    • add, commit

  3. Switch to master

  4. Generate additional commits on master!!

    • Please modify or create the same file!

  1. Merge to master

  2. Result -> merge conflict occurs

    You can check conflicted files with git status command.

  3. Check and resolve conflicts

  4. Proceed with merge commit

    • Vim editor screen will appear.

    • Check the automatically written commit message, press esc and type :wq to save and exit.

      • w : write

      • q : quit

    • Let's check the commit.

  5. Check graph

  6. Delete branch

Last updated