Introduction to Version Control

Apr 10 2024 · Git 2.44, Terminal, GitHub Desktop

Lesson 02: Using Git for Development

Git Commands Demo

Episode complete

Play next episode

Next
Transcript

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

git status

to confirm that the working directory is clean. In GitHub Desktop, the “Changes” tab shows zero changes. To use GitHub Desktop to make a new branch, I click on the “Current Branch” dropdown and type the name of a new branch in the text field. GitHub Desktop shows an extra dialog to confirm you want to create this branch. If you click “Create Branch”, GitHub Desktop creates and switches to the new branch.

Over in Terminal, type

git status

again to see that Terminal has also been switched to the new branch.

Open the recipe.md file and make a change. This week, the ratios of flours changed to 200g of bread flour, 150g of whole wheat flour, and 50g of all-purpose flour. After making the updates, save the file.

Click GitHub Desktop to make it the active app; the change appears with a diff. In the terminal, type git status again. It shows that the recipe.md file has been modified but that it isn’t staged for commit. GitHub Desktop displays things differently. The checkbox to the left of recipe.md in the “Changes” tab shows that it’s staged for the next commit. When using the terminal, you have to stage the changes before you commit, but when you use GitHub Desktop, you have to unstage changes before you make the commit.

In GitHub Desktop, you can enter the short and long descriptions in the text fields and click the “Commit to demo-branch” button.

But we forgot to make notes. Open the text file again and, at the bottom, update the notes to say you changed the ratio. In GitHub Desktop, open the “History” tab and right-click or control-click on the most recent commit to display the context menu. “Amend Commit…” is at the top. Select that, and GitHub Desktop brings you back to the “Changes” tab with the prior commit message in the text boxes. You can either update this message or click “Amend last commit”. Now, if you click the “History” tab, you can see both of the changes are part of the single commit.

You might have noticed some other items in that context menu. Here is also where you’d add a tag to a commit. Select the “image of score pattern” commit and add a tag: “best-score”.

Now that you’ve created a branch and made changes, the next section will show you how to merge the branch back into the main branch and what to do when it goes wrong.

See forum comments
Cinema mode Download course materials from Github
Previous: Everyday Git Commands Next: Merging Changes