Skip to content

laurenkahn/git-tutorial

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 

Repository files navigation

Git Tutorial

Install git

  1. Open the command line
  2. To check to see if you have git installed
git --version
  1. To install on a Mac, type (this will install a pared down version of XCode that includes git)
xcode-select --install
  1. For other operating systems, following these directions

Create an account on GitHub and join UO Data Science organization

  1. Go to GitHub to create an account
  2. Go to UO Data Science
  3. Add username to list on Slack to be added to the organization
  4. Accept email invitation

Why version control?

  • To have a backup
  • To be able to roll back to any previous version
  • To work collaboratively and avoid conflicted copies
  • To document your code and improve reproducibility
  • To make it simple to share your code
  • To avoid this:

Key concepts (Git 101)

  • Snapshots = records what the files look like at a given point in time
    • You decide when to take snapshots
    • History of all snapshots is retained
  • Staging = which files to include in the snapshot
    • You decide which files you want to take snapshots of
  • Commit = the act of creating a snapshot
    • Info that's been changed
    • A reference to the commit that came brefore it (parent commit)
  • Repository = collection of files and file history
    • Local repository = exists only on your local machine
    • Remote repository = exists on a remote website (e.g. github.com, gitlab.com, bitbucket.org)
  • Cloning = copying a repository
  • Pulling = grabbing changes from the original repository
  • Pushing = pushing changes to the original repository
  • Branches = offshoots of the master branch
    • Master = typically the main branch
  • Merging = combining branch with master repository

Basic process for local use

Image from git-scm.com

  1. Make changes to a file
  2. Stage the file
    • Choose to take a snapshot of the changes
    • git add [file]
  3. Commit the changes
    • Take a snapshot of the file
    • git commit -m "I made these changes.." [file]
  4. Rinse, repeat.

Tutorial

Local use

  1. Make directory on your desktop
mkdir ~/Desktop/git-test
cd ~/Desktop/git-test
  1. Initialize the repository
git init
  1. Check what's in the directory
ls -a
  1. Get status
git status
  1. Create file
printf "I <3 git" > test.txt
  1. Check status
ls 
git status
  1. Add test.txt file to the repository
git add test.txt 
  1. Check status
git status
  1. Save snapshot of repo by commiting changes
git commit -m "added test file"
  1. Check version history
git log

Basic process for remote and collaborative use

Image from Dirk Dunn

  1. Pull recent changes from remote repository
    • Get most up to date version of the repository
    • git pull
  2. Make changes to a file
  3. Stage the file
    • Choose to take a snapshot of the changes
    • git add [file]
  4. Commit the changes
    • Take a snapshot of the file
    • git commit -m "I made these changes.." [file]
  5. Push changes to remote repository
    • Apply your local changes to the repository
    • git push
  6. Rinse, repeat.

Remote use

  1. Update global configurations
git config --global --list
git config --global user.name 'Dani Cosme'
git config --global user.email 'dani.cosme@gmail.com'
git config --global core.editor 'sublime'
  1. Clone git-tutorial repo
cd ~/Desktop
git clone https://github.com/uodatascience/git-tutorial.git
  1. Check status
git status
  1. Get most up to date version of the repo
git pull
  1. Open favs.txt file with text editor
# open in text editor app
open /Applications/TextEdit.app favs.txt
# open in terminal using vim
vim favs.txt
  1. Add your favorite R package and save file
# add txt directly from command line
printf "\ndplyr" >> favs.txt
  1. Add favs.txt to the staging area
git add favs.txt
  1. Commit changes
git commit -m "added fav package"
  1. Push changes to github repo
# single master branch
git push

# multiple branches
git push origin [branch name]
  1. Pull newest version from the github repo
# single master branch
git pull

# multiple branches
git pull origin [branch name]

Commonly used commands

# initialize repository
git init

# add file(s) 
git add [file]  # single file
git add .       # all files

# make a snapshot of repository
git commit -m "[message text]"

# copy existing repository
git clone [repo address]

# get newest version of repository
git pull

# push changes to repository
git push

# view history
git log

# check changes that have been made to files in a repository
git diff

# create new branch
git checkout -b [name of new branch]

# switch branches
git checkout

# check configurations
git config --global --list

Resources

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published