Getting Started with Git and GitHub

Section 1: Intro and Git

Section 2: GitHub, Merging, and Branching


Section 3: Set up Git and GitHub, Clone a Repo, and Make a Commit

In the following steps, we will set up Git on our computers, cache our GitHub credentials, clone a repo, and make a first commit! We only need to do steps 1-4 once, so once you’ve completed them, you can skip them in the future and jump straight to step 5.

Step 1: If you don’t already have one, create a GitHub account and verify your email address.

Step 2: If you haven’t done so, email or Slack your user ID to Henrik, Kert, or Pravin so they can add you to the Berry Consultants GitHub team.

Step 3: Step up Git on your local computer.
a) Verify that you have Git version >= 2.0 on your computer

git --version

If Git is installed, you’ll get a message like “git version 2.xx.x (Apple Git-128)”. If not, download Git here.

b) Set your Git username by typing in the terminal:

git config --global user.name "yourGitHubusername"
git config --global user.name # to confirm that it worked correctly

c) Set your commit email address
Find your GitHub noreply email by following these instructions. Then, type into the terminal:

git config --global user.email "yournoreplyemail@email.com"
git config --global user.email # to confirm that it worked correctly

Step 4: Cache your GitHub credentials in Git (more detailed instructions here).
a) Test that the credential helper is installed by typing into the terminal:

git credential-osxkeychain

If you get a message like “> Usage: git credential-osxkeychain <get|store|erase>”, it’s installed. If not, type brew install git into the terminal. If you don’t have homebrew, install it at https://brew.sh/, then type brew install git into the terminal.

b) Tell Git to use osxkeychain credential helper by typing:

git config --global credential.helper osxkeychain 

c) Last, create a personal access token on GitHub by following these instructions. Save it in a safe place (like LastPass or another password manager). You’ll use it like a password when performing Git operations over HTTPS.

Git and GitHub are now set up! Since steps 1-4 only need to be done once on each computer, you won’t need to repeat them. Now you’re ready to clone your first repo!

Step 5: Clone a repo
Navigate to the folder where you’d like to keep the Berry Simulation Library repo. Make sure it’s not already a git repository by typing the following into the terminal:

git status # should tell you are not in a Git repo. if not, move out of the repo
git clone https://github.com/BerryConsultants/Shared-Trial-Simulation-Library.git # HTTPS address for this repo

You now have a local version of this repo on your machine.

Step 6: Push your first commit!
Add a new file to the repository, named with your initials (e.g. yourinitials.txt) by typing the following into the terminal:

cd Shared-Trial-Simulation-Library/testcommits/ # move into testcommits directory 
touch your-file-name # create a new file named yourinitials.txt 
git add your-file-name # stage your new file using its file name (yourinitials.txt)
git status # check the status of your new file
git commit -m"pushing my first commit to the Berry Code Library!" # commit with message
git push # push your additions to the remote repository

Congratulations! You’ve set up Git, GitHub, cloned a library, and pushed your first commit to a GitHub repo. You’re ready to explore all the great tools Git and GitHub have to offer! Check out your personal dashboard, follow some of your Berry colleagues, or create a new repo.

Setting up Git, GitHub, and Making your First Commit: Summary

drawing


Section 1: Intro and Git

Section 2: GitHub, Merging, and Branching