Set Up Your Git Scenario Environment

This stuff is a lot more fun if you try it out. Let’s create a sample repository to play with:

  1. Create a repository on GitHub.com and clone it to your desktop.
  2. Create a new branch, call it test.
  3. 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";
       }
      

:metal: You’re ready to rock! :guitar:

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 pushed your commits to your remote (or not). Look :eyes: for these drop downs throughout the course:

example of the "I didn't push" and "I pushed" drop downs

They will help you find the right instructions for each situation.

I need a refresher

Creating a Repository

  1. Navigate to GitHub.com
  2. Click the New repository button.
  3. Enter a name for the repository in the Repository name field.
    • You can also add a description for the repository in the Description field.
  4. Click the Initialize this repository with a README checkbox.
  5. Click the Create repository button.

Cloning a Repository

  1. Navigate to your repository on GitHub.com.
    • If you just created the repository, you are already there!
  2. On the Code tab, click the Clone or download button.
  3. Copy the Clone with HTTPS web url.
  4. Open a terminal application and navigate to a location on your local machine where you want the course repository to go.
  5. Enter: git clone URL, where URL is the web url you copied from your repository. This clones your repository to your local machine!
  6. Enter: cd REPONAME, where REPONAME is the name of the repository you just cloned to your machine.
Stuck? Open an issue in the repository for this class and mention @githubteacher for help from one of the GitHub trainers!
Continue