This stuff is a lot more fun if you try it out. Let’s create a sample repository to play with:
- Create a repository on GitHub.com and
clone
it to your desktop. - Create a new branch, call it
test
. - Create a series of commits that give you a rich history to practice the scenarios in this course. Feel free to use this handy script to generate them for you:
-
Bash:
for d in {1..6}; do touch file$d.md; git add file$d.md; git commit -m "adding file $d"; done - **PowerShell:** for ($d=1; $d -le 6;$d++) { touch file$d.md; git add file$d.md; git commit -m "adding file$d.md"; }
-
You’re ready to rock!
Using git log
If you type git log --oneline
, your commit history should include several commits that look something like this:
5950a1b adding file 4
Those first 7 characters are going to be unique to your machine and are a section of the SHA-1 hash assigned to that specific commit (the SHA-1 hash is 40 characters long). We are going to use that hash identifier a lot as we learn how to git
out of sticky situations.
New UI Addition
When trying to get out of a pickle, the best tool for the job is typically dependent on if you push
ed your commits to your remote (or not). Look for these drop downs throughout the course:
They will help you find the right instructions for each situation.
I need a refresher
Creating a Repository
- Navigate to GitHub.com
- Click the New repository button.
- Enter a name for the repository in the Repository name field.
- You can also add a description for the repository in the Description field.
- Click the Initialize this repository with a README checkbox.
- Click the Create repository button.
Cloning a Repository
- Navigate to your repository on GitHub.com.
- If you just created the repository, you are already there!
- On the Code tab, click the Clone or download button.
- Copy the Clone with HTTPS web url.
- Open a terminal application and navigate to a location on your local machine where you want the course repository to go.
- Enter:
git clone URL
, where URL is the web url you copied from your repository. This clones your repository to your local machine! - Enter:
cd REPONAME
, where REPONAME is the name of the repository you just cloned to your machine.