Learning Git and GitHub
1. Create your first repository
In this step you will learn how to create a new repository on your PC and add files to it.
Video Guide: GitHub Desktop 1 - Create your first repository
Use GitHub Desktop to create a new repository by selecting File > New Repository
Open and view your repository in Windows Explorer
Open and view your repository in your code editor
Add a file and make some changes
2. View and commit changes
In this step you will learn how to view and commit changes to your code.
Video Guide: GitHub Desktop 2 - View and commit changes
Make some changes to one of your files
Review the changes in GitHub desktop
Add a commit to "save" the changes to your repository
Use the "Discard Changes" command to "undo" changes
3. Undo and squash commits
In this step you will learn how to undo changes and "squash" commits.
Video Guide: GitHub Desktop 3 - Undo and squash commits
To undo changes:
Make and commit some changes
In GitHub Desktop, select the "History" tab in the commits pane
Choose a commit to undo, right click, and select either "undo commit" or "revert changes in commit"
- Undo Commit
Deletes the commit but not the changes. The changed files are now staged for a new commit.
- Revert Changes in Commit
Creates a brand-new commit that reverses the changes that were made. No files are staged for commit.
To "squash" commits:
Find two commits you want to "squash"
Drag one of them on top of the other
Choose a new commit message for the combined commits
4. Publish to GitHub
In this step you will learn how to publish your repository to GitHub, and what it means to fetch, push, and pull the origin.
Video Guide: GitHub Desktop 4 - Publish to GitHub
To publish to GitHub:
In GitHub Desktop, click the "Publish repository" button
Choose a repository name and location
To synchronize changes with GitHub:
Click the "Fetch origin" button to check for changes
Click the "Push origin" button to copy updates from your PC to GitHub
Click the "Pull origin" button to copy updates from GitHub to your PC
5. Resolve conflicts
In this step you will learn how manage and merge
Video Guide: GitHub Desktop 5 - Resolve conflicts
When pushing new commits, you will be prompted to fix file conflicts (if there are any)
For files that cannot be modified with a text editor (example: *.exe files), choose which version you would like to keep.
For files that can be modified with a text editor (example: code files)
Open the file in any text editor (I recommend VS Code, see above)
Find the sections that are surrounded by carats (
<<<<<<< ... >>>>>>)Decide which code you want to keep, or rewrite the code to combine the differences
Delete the carats that surround your fixed code
Make sure the file is saved
Continue with the merge
Push origin as needed
6. Create a branch
In this step you will learn how to create branches.
Video Guide: GitHub Desktop 6 - Create a branch
To create a branch:
In GitHub Desktop, select Branch → New Branch in the toolbar
Or you can click the "Current Branch" button and select "New Branch"
Name your branch
To switch between branches:
In GitHub Desktop, select the "Current Branch" drop-down and choose the branch you want to view
7. Merge your branch into main
In this step you will learn how to make pull requests and merge a branch into main.
Video Guide: GitHub Desktop 7 - Merge your branch into main
Select the "Preview Pull Request" option from the menu, and
Resolve any merge conflicts (see lesson 5 above)
Create a pull request
Merge the pull request. Make sure that your comments and title are descriptive.
Delete your branch (both on local and on cloud) if you are done with it
8. Clone an existing repository
In this step you will learn how to use the clone and fork commands.
Video Guide: GitHub Desktop 8 - Clone an existing repository
To clone a repository
In GitHub Desktop, choose File → Clone repository
if you already have access to this repository, you may be able to choose it from the list
You can also paste a web link using the "URL" tab of the clone window
To fork a repository:
Find the repository you want to make a copy of (on GitHub.com)
Select the Fork button in the upper right hand corner of the screen
Follow the steps above to clone the new repository to your PC
9. Go back to an older commit
In this step you will learn how to go back in history to view your code as it was in a previous commit. This is useful especially when debugging to find out at what point a bug was introduced into your code.
Video Guide: GitHub Desktop 9 - Go back to an older commit
In the History panel of GitHub Desktop, find the commit you want to view
Right-Click, and select "Create branch from commit"
Name the branch appropriately
10. Cherry-pick a commit
In this step you will learn how to use cherry-pick to copy a commit from one branch to another.
Video Guide: GitHub Desktop 10 - Cherry pick a commit
Make sure you are in the branch that contains the commit you want to cherry-pick
Right-click on a commit and select "Cherry pick"
Choose the branch you want to pick it into
Resolve any conflict