Intro to Source Control
via GitHub
Alex Higuera - Senior Software Engineer @ Cengage
February 27, 2021
Intro to Source Control
Via GitHub
Workshop GitHub repository: https://github.com/alexfigtree/reality-virtually-hackathon
GitHub’s Git cheat sheet:
https://education.github.com/git-cheat-sheet-education.pdf
Please refer to:
https://github.com/alexfigtree/cincyhacks/blob/master/README.md
Directions are there ^^ for installing the following:
Before we begin:
What we’ll do in this workshop:
Why do we need Git for this hackathon?
From WIKI:
Git is a version-control system for tracking changes in computer files and coordinating work on those files among multiple people.
It is primarily used for source-code management in software development, but it can be used to keep track of changes in any set of files.
TL;DR: If you’re working on a team and want to contribute, a git repository shared between team members is a great way of keeping track of who did what.
EX: Google Docs
Why do we need GitHUB for this hackathon?
GIT versus GitHUB:
Git: version control system/process. �(Free, open source)
GitHub: best known social web-based hosting service for Git, plus bug tracking, wikis, social code review, etc.
Part 1. Introduction:
Why Source Control?
Source control (or version control) is the practice of tracking and managing changes to code.
Version Control - Single Document
You’re already familiar with tracking changes within a single document.
Version Control - Whole Project
Git allows you to track changes to a repository (repo), which is an entire directory containing things like:
Git Terminology
a Commit ��A set of changes to one or more files, given a title and description.�
$ git status
On branch master
Changes to be committed:
modified: index.html� modified: README.md
all of these changes will be included in the commit
Commit Messages
Commit messages describe each set of changes:
Changes to be committed:
modified: index.html� modified: README.md
$ git commit --all --message “Fix spelling on front page”
2. Diff
Diff:
a way to view changes (differences) between files
$ git diff
<<Changes to your code shown here>>
3. Branches
Branch �A named chain of commits.
Provides sandboxes, ways to safely edit the project by several people.��Examples: �master or fix-shopping-cart
individual commit
4. Checkout
checkout �A way to switch between branches.
$ git status�On branch master
$ git checkout fix-shopping-cart�Switched to branch ‘fix-shopping-cart’
5. Clone/Copy - Getting a Copy of a repo
Official repo�github.com/facebook/react
Your copy�github.com/alice/react
fork
clone
Local copy on your machine��~/Documents/react
Making Changes: Add & Commit
Make Changes
Add changes to �Staging Area
Commit staged changes
git add *
git commit -m “...”
Making Changes: Add & Commit - GitHub Desktop
`git add`
`git commit -m ‘Update form.html’ `
`git diff`
Contributing Back
Official repo�github.com/facebook/react
Your copy�github.com/alice/react
Pull Request
pull
Local copy on your machine��~/Documents/react
push
Pull: downloads the latest changes from repo (refresh)
Push: sends changes you made to remote repo. (After you made some commits)
Git Advice and Best Practices
Git is Intimidating at First (It’s Not Just You)!
But it’s worth learning
Git makes it easy to recover from mistakes
Small and frequent commits are better than giant ones
Sync up with others frequently (Pull early and often!)
Learn the workflow and etiquette of your team
The GitHub.com Landscape: www.github.com
The GitHub.com Landscape: www.github.com
The GitHub.com Landscape: www.github.com
Creating a new repository on GitHub.com
We’ll review this in detail in the next section:
Part 1: Questions?
Part 2: Workshop
Section 2A: Creating your first repo:
Section 2B: Contributing to a shared repo:
Great reference: https://guides.github.com/activities/hello-world/
Part 2A: Creating your first repo
In this guide, we will learn to:
2A: Creating a new account on GitHub.com
2A: Next steps
2A: Creating a new repo with your account
Configure your new repo - include README:
Modify the README file in your new repo
Make updates to README
Preview changes before committing
End result: Changes made to your README:
Finished with 2A? Let’s continue with 2B:
Section 2B: Making local changes
In this guide, we will learn to:
Section 2B: Making local changes
Reference/detailed instructions: https://github.com/alexfigtree/cincyhacks
Before we begin, make sure you’ve:
Installing Git
Using Terminal or GUI
Text editor for code:
Section 2B: Find the repo
Git Bash or terminal:
Copy the web URL for use in terminal:
GitHub Desktop:
Open in GitHub Desktop:
https://github.com/alexfigtree/cincyhacks
Section 2B: Clone the repo
Git Bash or terminal:
GitHub Desktop:
Open in GitHub Desktop:
Section 2B: Make a local branch
Git Bash or terminal:
GitHub Desktop (yes, publish branch):
Git Bash or terminal:
$ git checkout add-myself-to-list
Section 2B: Making modifications
Section 2B: Committing your changes
GitHub Desktop: Changes should automatically show
Git Bash or terminal:
$ git diff
<<See changes here>>
$ git add .
$ git commit -m “personal-commit-message-here”
$ git pull
$ git push
→ 2. Write your commit message here
→ 3. Press this button
1. Pull the latest changes (will show as ‘Publish Branch’ if branch is new)
Section 2B: Confirming your commit
Go to the repo’s github url to see your commit - click on `main` dropdown and look for your branch name:
Submitting a Pull Request to add your changes to the Main branch
On your branch view, click on Compare & Pull Request:
Submitting a Pull Request to add your changes to the Main branch
Opening a PR:
Submitting a Pull Request to add your changes to the Main branch
PR Created!
Submitting a Pull Request to add your changes to the Main branch
Questions?
DONE!
Feel free to contact me via email:
THANK YOU AND GOOD LUCK!