The full text of this talk can be found here: https://josephdprein.github.io/version-control-workshop/
Version control systems like Git solve several common problems in software development:
Git can be installed on all major operating systems. Follow the steps for your platform:
brew install git
sudo apt install git
sudo dnf install git
sudo pacman -S git
sudo apt install git
git --version
in your terminal/command promptgit config --global user.name "Your Name"
git config --global user.email "your.email@example.com"
A Git repository is a project folder that Git tracks changes for.
Create a new folder and change into it:
mkdir my-first-repo && cd my-first-repo
Initialize a new git repository:
git init
git init
creates a new repository
git add <filename>
to stage specific filesgit add .
to stage all changesgit status
git commit -m "Descriptive message"
to save your changesgit log
This three-step process (edit → stage → commit) is the foundation of Git’s power:
Here are the most commonly used Git commands you’ll need to know:
git init
- Create a new repositorygit status
- Check what files are tracked/changedgit add <file>
- Stage changes for commitgit commit -m "message"
- Save staged changesgit log
- View history of commitsgit branch
- List branchesgit checkout <branch>
- Switch to a branchgit merge <branch>
- Combine branchesFor complete documentation, visit git-scm.com
First, create a new file called helloWorld.html
Add the following contents and save the file:
<html>
<body>
Hello, world!
</body>
</html>
Run git status
.
Git reports that the file helloWorld.html
is “untracked”, meaning that the changes aren’t being monitored by git yet.
You can track it by running git add helloWorld.html
. You’ll have to do this with any new files you add to your repository.
Now, commit your changes by running git commit -m "Add hello world file"
.
Run git status
once more; git will report nothing has changed since your last commit.
You can see a history of your commits with git log
.
Branches allow you to work on different versions of your code simultaneously.
Let’s make a new branch. We can call it whatever we want; how about “add-name”?
The name should ideally be descriptive of the changes you’re going to make.
Run git branch add-name
to create the new branch.
Switch to your new branch with git checkout add-name
.
Now, let’s make changes to our text file.
Replace the word “world” with your name.
While you’re at it, add something new on another line:
<html>
<body>
Hello, Joseph!
Here's an extra sentence.
</body>
</html>
Now, run git status
again.
It says we have ‘changes not staged for commit’;
git recognizes that our files have changed, but says we haven’t told it to do anything about it yet.
Run git add helloWorld.html
to stage your changes.
Run git diff --staged
to see the difference between your last commit and what you have staged.
Now, run git commit -m "Added my name and more content to helloWorld.html
.
Merging integrates changes from one branch into another.
Check out our original branch with git checkout main
.
Notice that your helloWorld.html
file is back as it was originally.
Merge your new branch into main with git merge add-name
.
Now, our main
branch has our changes from the other branch folded in.
GitHub is a cloud-based service that hosts Git repositories.
Go to github.com and sign up for a free account.
Choose a username; it should be one you’re comfortable sharing professionally.
Set up your profile with a photo and bio, if you want.
Forking creates your own copy of someone else’s repository.
You can make changes to your fork without affecting the original.
Your fork remains connected to the original repository; you can pull their changes into your fork when they update the code, or even open a pull request to ask them to fold your changes back into their code.
Let’s fork my sample github pages repository; it contains the text of this talk!
You can find it at https://github.com/josephdprein/version-control-workshop.
Click ‘Fork’ in the top right to create your own copy of the repository.
GitHub Pages lets you host websites directly from your repository.
To enable GitHub Pages:
Your site will be published at https://yourusername.github.io/version-control-workshop/
Any changes pushed to the main
branch will automatically update your live site
Cloning downloads a repository to your local machine.
When you forked this repository in the previous step, it made a copy of it on your own github.
From the page of your fork, click the ‘Code <>’ dropdown button and copy the URL.
Clone the repo to your computer by running git clone <URL>
, replacing <URL>
with the URL you copied.
After cloning a repository, you can modify files and track those changes:
git add
Pushing uploads your local commits to GitHub:
git push origin main
There are many topics we didn’t cover today.
In time, you should learn how to do things like fix your mistakes, resolve merge conflicts, rebase your branches, and open pull requests.
These are all common things you’ll need to do when collaborating with other people on a repository.
However, what we covered today should be enough to get you started, and you can learn the other stuff as you need to use it.
Further reading: The Pro Git Book How to undo (almost) anything with Git How to Write A Git Commit Message