GitHub Branching and Merging using GitHub Desktop

Alexandra Z Harner
5 min readSep 11, 2020

--

In this article, we first create a repository on github.com

Step 1- Create a new repo in github.com

Create a new repo in github.com by clicking the top-right icon “+” and click “New repository” in github.com.

Now you have a new GitHub repository. It can be private or public.

Step 2 —Add a file README.md in github.com

Add a file REDEME.md in github.com.

Github is similar to a markup language that embeds pictures, makes the text a title, or bold.

Here is a sample

# EEC521courseproject
Fall 2020 Course Project

<b>Project Title</b>: A Puzzle Recongizer Web App

<b>User Story</b>:

When John clicks the button “Upload”, he is able to upload a photo with a puzzle, the Puzzle Recognizer will interpret the numbers in the puzzle, and load into the existing puzzle grid.

<b>Step 1 — Select an puzzle image</b>

![Alt text](https://i.imgur.com/mSiaV39.png)

<b>Step 2 — Select an puzzle image file</b>

![Alt text](https://i.imgur.com/ikVOBFA.png)

<b>Step 3 — The puzzle will be loaded to the grid. </b>

![Alt text](https://i.imgur.com/hSEFCS5.png)

The README.md will look like

Step 3 — Clone a repository in GitHub Desktop

Clone a repository. Within GitHub Desktop (you will need to download GitHub Desktop at https://desktop.github.com/ which includes GitHub Desktop for Windows and macOS). Click “File”, click “Clone repository …”

Note that within GitHub Desktop, you need to click “File”, Click “Options”, click “Accounts” to log in using your Github username and password.

Step 4 — Add one file in the default “master” branch

After the clone, within GitHub Desktop, click “Repository”, click “Show in Explorer”

In the File Explorer, create a file “LocalFile.txt”, edit it, and save it.

Back to the GitHub Desktop, commit the file (it will save to the local repository) by clicking “commit to master”, and push it to github.com by clicking “Push origin”. See the pictures below.

Click “Commit to master” to save the change in local repository
Click “Push origin” to upload the change to github.com server

After “push origin”, your “LocalFile.txt” will show up in your github.com course repository. See below

Step 5 — Create A New Branch “myFirstBranch”

Go back to GitHub Desktop, create a new branch. Click “Branch” at the top, click “New branch …”

Name it as myFirstBranch in the “Create a branch” dialogue.

Now you have two branches, the default “master” branch and the new branch “myFirstBranch”.

Step 5 — Change file content in the “master” branch

Within GitHub Desktop, in the “master” branch, click “Repository”, and click “Show in Explorer”

Note that if you are not in “master” branch, you need to switch to it

Edit the LocalFile.txt, save the file.

Switch to Desktop GitHub, click “Commit to master”, and also click “push origin” (picture not given).

Step 6 — Change file content in the “myFirstBranch” branch

Now, switch the branch to “myFirstBranch”

in the “myFirstBranch” branch, click “Repository”, and click “Show in Explorer”. Edit the LocalFile.txt, save it.

Back to GitHub Desktop, commit, and push this file. Commit the file by click “Commit to myFirstBranch”, and then click “Push Origin”.

In github.com, you will see that the new File content in the “myFirstBranch”.

Step 7 — Merge Two Branches and Solve the Conflict Manually

With GitHub Desktop, click “Branch”, make sure the current branch is chosen as “master”. Click “Merge into current branch”

in “Merge into master” dialogue, click “myFirstBranch”

a pop-up dialogue will show “1 conflicted file”.

Click “Open with default program”, the notepad will show up, and you can manually solve the conflict by editing the file.

Manually delete some lines.

After manually solve the conflict, you can see the new merged file LocalFile.txt in github.com

You can view your commit history by clicking “[Number] commits”.

The merge branch “MyFirstBranch” is shown in the commit history.

The end.

--

--

Alexandra Z Harner

I am a hands-on software consultant who enjoys bringing smiles to people. My site https://www.createclassicsudoku.com ranks 1st when you google “make sudoku”