Skip to the content.

What is Git & GitHub? – Create & Merge Branches

🇯🇵 日本語版: 02_Branches.md

This section goes over Git branches and how to work with your first branch.

Overview Overview

git branch command

  1. First, go back to the learning_git repository

     cd Documents/learning_git
    
  2. Use git branch command to see all of the branches in your repo & which branch you are currently on.

     git branch
    
     * main
    

git branch

Create a new branch

First, let’s create a branch named develop and switch to it.

  git checkout -b develop

  ...

  Switched to a new branch 'develop'

git checkout -b <branch name>

Add a file to the develop branch

  1. Create a file on the develop branch

     touch develop_file.md
    
  2. Use git add & git commit commands to save it in your local repo

     git add develop_file.md
     git commit -m "develop only"
    
     [develop 4f98baf] develop only
     1 file changed, 0 insertions(+), 0 deletions(-)
     create mode 100644 develop_file.md
    
  3. Use git status command to verify changes

     git status
    
     On branch develop
     nothing to commit, working tree clean
    
  4. Use git push command to upload changes to GitHub

     git push -u origin develop
    
     Enumerating objects: 4, done.
     Counting objects: 100% (4/4), done.
     Delta compression using up to 4 threads
     Compressing objects: 100% (2/2), done.
     Writing objects: 100% (3/3), 277 bytes | 277.00 KiB/s, done.
     Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
     remote: This repository moved. Please use the new location:
     remote:   https://github.com/ahandsel/learning_git_3.git
     remote:
     remote: Create a pull request for 'develop' on GitHub by visiting:
     remote:      https://github.com/ahandsel/learning_git_3/pull/new/develop
     remote:
     To https://github.com/ahandsel/learning_git_3.git
     * [new branch]      develop -> develop
     Branch 'develop' set up to track remote branch 'develop' from 'origin'.
    

Verify on GitHub Desktop App

Let’s verify the changes by viewing it on the GitHub Desktop App

  1. Open the app with the following command:

     cd learning_git
     github .
    
  2. App will open to a Add Local Repository setting page, click the Add Repository button

  3. Click History Tab to view the changes you have made

    • GitHub_Desk_Verify_1

See the changes on GitHub

Go to the Network graph setting on your GitHub repo to see the changes you have made

     
Gif_GitHub_Demo 02_Branches_GitHubNetwork 02_Branches_NetworkExample

Create & Merge a Pull Request

Pull RequestsSo, you can check other users’ changes etc. before the file is actually changed.

developCreate in mainGitHub to merge the branch into the branch.Pull request

Gif_GitHub_Dojo_PullRequest

mainYou see two new files in your branch!

Example_Pull_Request

Update local repo from GitHub repo

main Let’s move to the branch.

git checkout main

Currently, GitHub repositories have more up-to-date files than local repositories.

  Switched to branch 'main'
  Your branch is behind 'origin/main' by 4 commits & can be fast-forwarded
    (use "git pull" to update your local branch)

Use the git pull command to handle this.

Pull the latest version of the repo from GitHub with git pull origin main

git pull origin main
remote: Enumerating objects: 1, done.
remote: Counting objects: 100% (1/1), done.
remote: Total 1 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (1/1), 631 bytes | 210.00 KiB/s, done.
From https://github.com/ahandsel/kintone_dojo
* branch            main     -> FETCH_HEAD
  5f9f89b..1438ca5  main     -> origin/main
Updating d775d42..1438ca5
Fast-forward
2nd_file.md     | 0
develop_file.md | 0
2 files changed, 0 insertions(+), 0 deletions(-)
create mode 100644 2nd_file.md
create mode 100644 develop_file.md

Now the mainbranch and developthe branch are in the same state,
so developlet’s delete the branch.

git branch -d develop
  Deleted branch develop (was c6e6c83).

git branchLet’s check with the command

git branch
  * main

What is Git Branch?

What is a branch?

Why use a branch?

02_Branches_GitBranches

Ref: Git - Branches in a Nutshell

Branch and website

mainIn the branch, there is code that runs the website.

If two developers want to change their website at the same time, create three branches

When development is complete, merge the branches!

02_Branches_Web

Git Push vs Pull –Teamwork

git push git pull
Upload command Download command
“Push” forces changes to the target repository. “Pull” gets changes from the target repository
[あなたのコード] ⟾ プッシュ ⟾ [ターゲット] [あなたのコード] ⏎ プル ⏎ [ターゲット]
A “push request” is a target repository that requests you to push changes. A “pull request” is to request the target repository to get changes.
02_Branches_Push 02_Branches_Pull

Hands-on C Review

   
git checkout -b develop Command to switch branches
Reasons to use a branch Separate code development, testing, public version, etc.
Pull RequestsWhengit pull A “pull request” is to request the target repository to get changes.

GitHub Workflow

Understanding the GitHub flow - GitHub Guides

02_Branches_GitHubWorkflow.png

# Step Notes
1 Create a branch mainfeatureCreate a branch from and start development
2 Commit changes After the code implementation is complete, commitcreate. You\
commitcan check the change history by creating, and you can roll back and refer to it.    
3 Open a Pull Request When you’re ready to share your implementation with others, create a Pull Request.
Four Discuss & Review Code Get code reviews from teen members and discuss them.
Five Deploy & Test Deploy the code to your test environment to make sure it works.
6 Merge to main The implementation is now in effect and the Pull Request keeps a record of changes to your code.

Detailed Overview of the GitHub Workflow

02_Branches_GitHubWorkflow_Overview

Git Common-Flow 1.0.0-rc.5 –Git Common Flow


GitHub Overview-GitHub Website Overview

GitHub Repository

02_Branches_GitHub_Bar_Code

GitHub Repository –Code

GitHub Issues

02_Branches_GitHub_Bar_Issues

GitHub Pull Request

02_Branches_GitHub_Bar_PullRequest

Overview of GitHub

Project boards: Task boards in KANBAN format

Wiki: Allows you to create and save related project documents

Insight: Repository analysis tool

GitHub parts

   
Branch Code alternative timeline\
example: main, Development, Feature / xxx  
Commit Save file changes to repository
Pull Request Share your proposed changes with others
Merge Pull Request Actually change the branch (main etc.) and update

Quiz time

Next Section

Revert - 03_Revert_EN.md

List of Lecture Guides

README_EN.md ⚙️