Git & Github

Tools for robust, collaborative coding

Computational Toolbox

  1. Unix Shell: Organize and edit file system.
  2. R: Computational enrivonment to make data products to write to file system.
  3. git: Track changes to files on files system.

git

  • Free and open-source command line tool
  • Developed to help coordinate collaborative coding
  • 99% of software projects use it
  • Many scientific projects use it

What does it do?

git allows you to
    save your work,
    document your process,
    share it and,
    collaborate with others.

Git commands to get started

Each command is called from the command line following git (e.g. git init).

  • init: initialize a repository (repo)
  • add: move a file into the staging area
  • commit: take a snapshot of files in the staging area with a message (-m)
  • push: send commits to another repo

  • init: invite the photographer (git) to the wedding (repo)
  • add: move the bride and groom into the camera frame
  • commit: take a picture of the bride and groom and caption it
  • push: share the photos online

  • init: invite the photographer (git) to the wedding (repo)
  • add: move the bride and groom into the camera frame
  • commit: take a picture of the bride and groom and caption it
  • push: share the photos online
mkdir wedding
cd wedding
git init
git add bride groom
git commit -m "cutting the cake"
git push

Example 1: Demo Project

mkdir demo-project
  1. Create new directory for my project.

mkdir demo-project
cd demo-project
  1. Create new directory for my project.
  2. Move into that directory.

mkdir demo-project
cd demo-project
git init
  1. Create new directory for my project.
  2. Move into that directory.
  3. Initialize git repo.

mkdir demo-project
cd demo-project
git init
echo "# My First Project" > README.md
  1. Create new directory for my project.
  2. Move into that directory.
  3. Initialize git repo.
  4. Create file using echo cmd (not git).

mkdir demo-project
cd demo-project
git init
echo "# My First Project" > README.md
git add README.md
  1. Create new directory for my project.
  2. Move into that directory.
  3. Initialize git repo.
  4. Create file using echo cmd (not git).
  5. Add file to staging area.

mkdir demo-project
cd demo-project
git init
echo "# My First Project" > README.md
git add README.md
git commit -m "initial commit"
  1. Create new directory for my project.
  2. Move into that directory.
  3. Initialize git repo.
  4. Create file using echo cmd (not git).
  5. Add file to staging area.
  6. Commit the change with message.

mkdir demo-project
cd demo-project
git init
echo "# My First Project" > README.md
git add README.md
git commit -m "initial commit"
# edit file
  1. Create new directory for my project.
  2. Move into that directory.
  3. Initialize git repo.
  4. Create file using echo cmd (not git).
  5. Add file to staging area.
  6. Commit the change with message.
  7. Make changes to file.

mkdir demo-project
cd demo-project
git init
echo "# My First Project" > README.md
git add README.md
git commit -m "initial commit"
# edit file
git add README.md
git commit -m "Add project description"
  1. Create new directory for my project.
  2. Move into that directory.
  3. Initialize git repo.
  4. Create file using echo cmd (not git).
  5. Add file to staging area.
  6. Commit the change with message.
  7. Make changes to file.
  8. Add file to staging area.
  9. Commit the change with message.

mkdir demo-project
cd demo-project
git init
echo "# My First Project" > README.md
git add README.md
git commit -m "initial commit"
# edit file
git add README.md
git commit -m "Add project description"
git log --oneline
  1. Create new directory for my project.
  2. Move into that directory.
  3. Initialize git repo.
  4. Create file using echo cmd (not git).
  5. Add file to staging area.
  6. Commit the change with message.
  7. Make changes to file.
  8. Add file to staging area.
  9. Commit the change with message.
  10. View the commit history.

GitHub

What does it do?

git allows you to
    save your work,
    document your process,
    share it and,
    collaborate with others.

GitHub

GitHub

  1. Allows you to create web-hosted repos to share with others
  2. “Facebook for coders”
    • Individuals or projects have their own accounts/profiles
    • Can follow one another

Create a repo

Live Coding to set up https://github.com/andrewpbray/demo-project.git

Sharing your work

Sharing your work

  • remote add: link your camera to the online album
  • push: sync photos with online album
git remote add wedding-pics wedding-pics.com
git push -u wedding-pics main

git remote add origin https://github.com/andrewpbray/demo-project.git
  1. Add new remote repo called origin.

git remote add origin https://github.com/andrewpbray/demo-project.git
git push -u origin main
  1. Add new remote repo called origin.
  2. Push all commits in local repo to remote

Next Steps

Survey

  1. Prompt you to set up GitHub account.
  2. Guide you through git installation.
  3. Guide you through git configuration.

GitHub Classroom

  1. We will post a link to Ed with a Demo Project link.
  2. When you click it, you’ll get a new repo in your account.
  3. You will clone the repo locally, work on it, then push your work.