Git/C2/Merging-and-Deleting-branches/English
Title of script: Merging and deleting branches
Author: Priya K
Keywords: Video tutorial, git, branch, merging, deleting, revert merging
|
|
Slide 1:
Merging and deleting branches |
Welcome to the spoken tutorial on Merging and deleting branches. |
Slide 2:Learning Objectives
|
In this tutorial, we will learn about
|
Slide 3:
System requirement
|
For this tutorial, I am using
You can use any editor of your choice. |
Slide 4:
Pre-requisites
|
To follow this tutorial
|
Earlier in the series, we learnt to create branches.
| |
Slide 5:
Merging diagram
|
This diagram illustrates how the new-module branch is merged with the master branch.
|
Slide 6:
After Merging
|
After merging, the commits of new-module are added to master branch.
|
Press Ctrl+Alt+T to open the terminal | First, we will open our Git repository mywebpage which we created earlier.
|
Type cd mywebpage and press Enter | To go into our Git repository, type cd space mywebpage
|
I will continue to use html files for demonstration.
| |
From here onwards, please remember to press the Enter key after typing every command on the terminal. | |
Type git branch and press Enter
|
Let us check the branch list by typing git space branch.
|
Highlight new-chapter >> Highlight master | The new-chapter branch was created earlier in this series and master is the default branch. |
Highlight * master | Currently, we are in the master branch. |
Type git log --oneline and press Enter | We will check the Git log by typing git space log space hyphen hyphen oneline |
Type git checkout new-chapter and press Enter | Let’s go to new-chapter branch and check the Git log.
|
Type git log --oneline and press Enter | Type git space log space hyphen hyphen oneline |
Now we will compare the commits of master and new-chapter branches. | |
Highlight the first 4 commits of master and new-chapter branch | These four commits are common to both the branches. |
Highlight Added story.html in new-chapter branch
|
“Added story.html in new-chapter branch is in new-chapter branch.
|
After merging, “Added story.html in new-chapter branch” commit will be added in the master branch.
| |
Type git merge master and press Enter | Let me demonstrate how to merge now.
|
Gedit opens up automatically to receive the commit message.
| |
Highlight the first line of gedit
|
I use the default commit message as it is.
|
Type git log --oneline and press Enter | We will check the Git log again. |
Highlight the commits | You can see that the commits of master branch are merged with new-chapter branch. |
Highlight the merge commit message | You can also see a commit message for the merging. |
Type git checkout master and press Enter | Next, we will go to master branch and check the commits.
|
Type git log --oneline and press Enter | Let’s check the Git log.
|
Highlight the Git log | Ideally, we should have merged the new-chapter branch to the master branch.
|
So, how can we revert this merging? | |
For this, we will have to go back to the new-chapter branch. | |
Type git space checkout space new-chapter | Type git space checkout space new-chapter |
Type git reset --hard HEAD~ and press Enter | To revert the merge, type git space reset space hyphen hyphen hard space HEAD tilde |
Highlight HEAD~ | Recall that latest revision is always HEAD and latest minus 1 revision is always HEAD tilde.
|
Type git log --oneline and press Enter | Let’s check the Git log once again. |
We can see that the merging is discarded now.
| |
We will now merge the new-chapter branch to the master branch. | |
Type git checkout master and press Enter | We will go to master branch first by typing git space checkout space master |
Type git log --oneline and press Enter | Let’s check the Git log again. |
Type git merge new-chapter and press Enter
|
To merge, we will type git space merge space new-chapter
|
Type git log --oneline and press Enter | Again check the Git log. |
We can see that our new-chapter branch has been successfully merged to the master branch. | |
Type git merge new-chapter and press Enter | Let’s try to merge it again.
|
Highlight “Already up-to-date” | Now we see a message that says “Already up-to-date”.
|
After merging, the new-chapter branch can be deleted from the Git repository. | |
Type git branch -d new-chapter and press Enter | To delete the branch, type git space branch space hyphen d space new-chapter |
Type git branch and press Enter | Let’s check the branch list once again by typing git space branch
|
Highlight -d in the deleting command | To delete a branch without merging, use hyphen D in uppercase instead of hyphen d in lowercase.
|
With this, we come to the end of this tutorial. | |
Slide 7:
Summary
|
Let us summarize.
|
Slide 8:
Assignment
|
As an assignment
|
Slide 9:
Acknowledgement
|
The video at the following link summarises the Spoken Tutorial project.
|
Slide 10:
Spoken Tutorial Workshops
|
The Spoken Tutorial Project Team conducts workshops and gives certificates to those who pass online tests.
|
Slide 11:
Acknowledgement
|
Spoken Tutorial Project is funded by NMEICT, MHRD, Government of India.
|
This is Priya from IIT Bombay. Thanks for joining. |