Introduction to Version Control

Apr 10 2024 · Git 2.44, Terminal, GitHub Desktop

Lesson 02: Using Git for Development

Merging Demo

Episode complete

Play next episode

Next
Transcript

Here, you can see GitHub Desktop and the terminal are both pointing to the demo-branch branch of our bread repo from the last demo. In Terminal.app, I can use

git status

to confirm that the working directory is clean. In GitHub Desktop, the “Changes” tab shows zero changes.

When you click the “Current Branch” dropdown in GitHub Desktop, you can see at the bottom a “Choose a branch to merge into demo-branch” button. Clicking this gives you a window from which you can select a branch to merge into this branch.

To make for an interesting demo, create a conflict first. In demo-branch, edit the first line of readme.md to read #README TITLE and save. Commit this change to the repository.

Now, switch to the main branch. Edit the first line of readme.md to read **README** and save. Commit the change.

At this point, the same line of readme.md has been changed in both branches.

In GitHub Desktop, all your options are presented simultaneously. You can see the conflicted line in the diff view, and there’s a popup allowing you to abort the merge or resolve the conflicts. Click the dropdown, and you can pick either the file from main or the file from demo-branch. You also can open the file using an editor.

Choose to resolve the conflict by choosing one of the two versions from the dropdown. Now, GitHub Desktop says the conflict is resolved and the merge can continue.

You saw that you could abort the commit. But what about resetting the commit? GitHub Desktop doesn’t offer that option. If you select the latest commit from the “History” tab, you get an option to “Revert” the commit. This is almost the same as a reset. It creates a new commit that undoes the changes. Once you do that, it makes a commit message and a new commit.

See forum comments
Cinema mode Download course materials from Github
Previous: Merging Changes Next: Conclusion