Menu

Log in

Sign up

From beginner to master of web design, coding, infrastructure operation, business development and marketing

  • COURSES
  • HTML & CSS Introduction
  • HTML & CSS Coding with AI
  • Linux Introduction
  • Docker Basics
  • Git & GitHub Introduction
  • JavaScript Coding with AI
  • Django Introduction
  • AWS Basics
  • Figma Introduction
  • SEO Tutorial for Beginners
  • SEO with AI
  • OTHERS
  • About
  • Terms of Service
  • Privacy Policy

© 2024 D-Libro. All Rights Reserved

Git & GitHub IntroductionChapter 5. Work With Branches

Branch Operation Basic Life Cycle

Branch Operation Basic Life Cycle

Git Branch Operation Lifecycle Steps

On this page, we'll explain a basic life cycle for the branch operation in seven steps.

Step 1: Create a new branch

As a default setting, you are working on the master branch. Edit and commit operations explained in the previous chapter were conducted on the master branch.

When you want to separate your work from the master branch, you need to create a new branch by running the git branch [new branch name] command.

Step 2: Check the branch status

To check your branch status (i.e., the list of branches and the current branch) in the command line, you need to run the git branch command. When you specify a branch name, the command creates a new branch. For checking status purposes, you simply run the command without any parameter.

Step 3: Switch branches

When you create a new branch by running the git branch [new branch name] command, you are still on the original branch; if you are creating a new branch for the first time, you are still on the master branch. To move to the new branch, you have to run one of the following commands

  • git checkout [branch name]
  • git switch [branch name]

Previously, the git checkout command was used only as an option to do this, however, git switch command was introduced as a substitute for git checkout command. Currently, you can use both commands to get the same result.

Step 4: Edit and Commit on branches

We already explained edit and commit operations in the previous chapter. The edit and commit operations can be applied regardless of the branch you are working on. What you may need to be careful of is on which branch you are operating. When you make a commit, the commit is applied to a specific branch on which you are operating.

Step 5: Integrate branches

There are two ways to integrate branches: Merge and Rebase.

Merge is used to join two or more development histories together. You can merge branches by running git merge in your command line. Rebase is used to reapply commits on top of another base branch. The command to implement rebase is git rebase.

Both merge and rebase operations can be done on the GitHub platform. On GitHub, rebase is one option of the merge action. The merge operation on the GitHub platform will be explained in the next chapter.

Step 6: Manage conflicts

If there are changes in the same line of code on different branches, the Git system cannot merge those branches automatically. This situation is called conflict. You need to resolve conflicts before merging the branches. You can manually fix the lines of code to resolve conflicts.

Step 7: Delete an unused branch

A merged branch is not automatically deleted unless you delete it. After several branching and merging operations, you may see many unused branches in your repository. To delete a branch, you can use the git branch -d [branch name] command.

In the following pages, you’ll learn how to manage branches in more detail.


You can also learn this topic offline. Click AmazonKindle.

More Topics to Explore

Changing File and Directory Owners with chown Command

chown (Change Owner of File and Directory)

Configuring Unit Files in Linux

Unit File

Setting Up Git & GitHub on Windows

Key Tool Preparation (2) – Windows

Removing Users from Linux

userdel (Delete User)

Understanding User, Group, and Permissions in Linux

What Are User, Group And Permission in Linux?

Changing File and Directory Owners with chown Command

chown (Change Owner of File and Directory)

Configuring Unit Files in Linux

Unit File

Setting Up Git & GitHub on Windows

Key Tool Preparation (2) – Windows

Removing Users from Linux

userdel (Delete User)

Understanding User, Group, and Permissions in Linux

What Are User, Group And Permission in Linux?

Tags:

Branch

Merge

Conflict

Git & GitHub Introduction
Course Content

Chapter 1. Git & GitHub Overview

What Is Git?

What Is Version Control?

How To Save Versions in Git?

Collaborating on Git & GitHub – Remote Repository

Collaborating on Git & Git Hub – Branch

Git & GitHub Basic Life Cycle

Chapter 2. Git & GitHub Initial Settings

Git & GitHub Initial Settings Overview

Key Tool Preparation (1) – Mac

Key Tool Preparation (2) – Windows

Key Tool Preparation (3) – Linux Remote Server

Git User Settings – git config

Create GitHub Account

GitHub Access Authentication Settings

Generating PAT (Personal Access Token)

GitHub SSH Setup

Chapter 3. Git & GitHub Project Setup

Three Cases in Git & GitHub Project Setup

Git & GitHub Project Setup Overview in Different Cases

Building Remote Collaboration Practice Environment

Project Initiator – Key Steps To Launch Git Project

Project Initiator – Create Local Repository (git init)

Project Initiator – Make the First Commit

Project Initiator – .gitignore File

Project Initiator – Create Remote Repository

Project Initiator – Link Between Remote and Local Repositories (git remote add)

Project Initiator – Upload Local Repository to Remote Repository (git push)

Project Initiator – Grant Remote Repository Access to Project Members

Project Member – Start Project As Collaborator

Project Member – Create Copy of Project Code on Local Computer (git clone)

Non-Member – Start Project With Replica of Existing Repository (Fork)

Fork vs. Clone

Chapter 4. Edit & Commit

Git Regular Workflow – Edit & Commit

Edit and Commit Overview (1)

Add Files to Staging Area – git add

Commit Files – git commit

HEAD and INDEX

Check Status of Working Tree and Staging Area – git status

Check Commit Histories – git log

Check Differences – git diff

Restore Files to Working Tree – git restore

Undo Changes – git reset

Delete Files – git rm

Edit and Commit Overview (2)

Chapter 5. Work With Branches

Git Regular Workflow – Work With Branches

What Is Branch?

Branch Operation Basic Life Cycle

Create Branch and Check Branch Status – Git Branch

Switch Current Branch (1) – Git Checkout

Switch Current Branch (2) – Git Switch

Merge Branches – Git Merge

Fast-Forward Merge

Non-Fast-Forward Merge (No Option)

Non-Fast-Forward Merge (--no-ff Option)

Squash Merge

Rebase Branch – Git Rebase

Managing Conflict

Stash Changes – Git Stash

Chapter 6. Remote Collaboration

Git Regular Workflow – Remote Collaboration

Remote Collaboration Overview

Link With Remote Repository – Git Remote

Upload to Remote Repository – Git Push

Download Remote Repository and Merge to Local Repository – Git Pull

Get Remote Repository Information to Local Repository – Git Fetch

Pull vs. Fetch

Request for Review and Merge – Pull Request

Merge Operation Using GitHub

Chapter 7. Supplemental Topics

Git Key Commands and GitHub Key Features

Git & GitHub Glossary

GitHub Other Features

Chapter 1. Git & GitHub Overview

What Is Git?

What Is Version Control?

How To Save Versions in Git?

Collaborating on Git & GitHub – Remote Repository

Collaborating on Git & Git Hub – Branch

Git & GitHub Basic Life Cycle

Chapter 2. Git & GitHub Initial Settings

Git & GitHub Initial Settings Overview

Key Tool Preparation (1) – Mac

Key Tool Preparation (2) – Windows

Key Tool Preparation (3) – Linux Remote Server

Git User Settings – git config

Create GitHub Account

GitHub Access Authentication Settings

Generating PAT (Personal Access Token)

GitHub SSH Setup

Chapter 3. Git & GitHub Project Setup

Three Cases in Git & GitHub Project Setup

Git & GitHub Project Setup Overview in Different Cases

Building Remote Collaboration Practice Environment

Project Initiator – Key Steps To Launch Git Project

Project Initiator – Create Local Repository (git init)

Project Initiator – Make the First Commit

Project Initiator – .gitignore File

Project Initiator – Create Remote Repository

Project Initiator – Link Between Remote and Local Repositories (git remote add)

Project Initiator – Upload Local Repository to Remote Repository (git push)

Project Initiator – Grant Remote Repository Access to Project Members

Project Member – Start Project As Collaborator

Project Member – Create Copy of Project Code on Local Computer (git clone)

Non-Member – Start Project With Replica of Existing Repository (Fork)

Fork vs. Clone

Chapter 4. Edit & Commit

Git Regular Workflow – Edit & Commit

Edit and Commit Overview (1)

Add Files to Staging Area – git add

Commit Files – git commit

HEAD and INDEX

Check Status of Working Tree and Staging Area – git status

Check Commit Histories – git log

Check Differences – git diff

Restore Files to Working Tree – git restore

Undo Changes – git reset

Delete Files – git rm

Edit and Commit Overview (2)

Chapter 5. Work With Branches

Git Regular Workflow – Work With Branches

What Is Branch?

Branch Operation Basic Life Cycle

Create Branch and Check Branch Status – Git Branch

Switch Current Branch (1) – Git Checkout

Switch Current Branch (2) – Git Switch

Merge Branches – Git Merge

Fast-Forward Merge

Non-Fast-Forward Merge (No Option)

Non-Fast-Forward Merge (--no-ff Option)

Squash Merge

Rebase Branch – Git Rebase

Managing Conflict

Stash Changes – Git Stash

Chapter 6. Remote Collaboration

Git Regular Workflow – Remote Collaboration

Remote Collaboration Overview

Link With Remote Repository – Git Remote

Upload to Remote Repository – Git Push

Download Remote Repository and Merge to Local Repository – Git Pull

Get Remote Repository Information to Local Repository – Git Fetch

Pull vs. Fetch

Request for Review and Merge – Pull Request

Merge Operation Using GitHub

Chapter 7. Supplemental Topics

Git Key Commands and GitHub Key Features

Git & GitHub Glossary

GitHub Other Features