Skip to content

Instantly share code, notes, and snippets.

@stephlocke
Created August 8, 2022 14:22
Show Gist options
  • Save stephlocke/e357af5c05b5047ef3d9cdfaf2f6d5e4 to your computer and use it in GitHub Desktop.
Save stephlocke/e357af5c05b5047ef3d9cdfaf2f6d5e4 to your computer and use it in GitHub Desktop.
A brief intro to Git!

Source control

Source control concepts

Source control is a system for tracking changes to files over time.

What's the point?

  • No version hell
  • Why did I do that?
  • Satisfy auditors
  • UNDO, UNDO, UNDO!!

What techs are there?

  • Central systems like SVN
  • Distributed systems like Git
  • Hybrid systems like TFS

Why GitHub?

  • Git is awesome
  • Public / private models
  • Great UX
  • Great integrations

(@cthydng) git model

Git glossary

  • Repository: Your project and it's history
  • Remote: The (TFS/GitHub/VSO etc) server
  • Clone:Take a linked copy of a repository
  • Fork: Take an unlinked copy of a repository
  • Pull: Update your copy of a repository
  • Add: Include a file in a change
  • Commit: Make the latest state of all the added files the new default state
  • Push: Update the central copy of the repository with your commits

Learning resources

Getting started

Your local workflow

git config --global user.name "John Doe"
git config --global user.email johndoe@example.com

Add git to existing projects

  • Tools > Version Control > Project Setup
<iframe width="560" height="315" src="https://www.youtube.com/embed/jYkaGwoO1q4" frameborder="0" allowfullscreen></iframe>

Committing your code - in a GUI

  • Select changed / new / deleted files to commit
  • Hit "Commit"
  • Add Short tile for change
  • Hit Enter, and add details
  • Hit commit
git init
git add somefile.R
git commit -m "Some message"

Exercise

  1. Add git to a directory
  2. Commit some code

Your distributed workflow

Using existing repos

  • Get a URL
  • File > New Project > Version Control > Git
  • C&P URL

Exercises

  1. Go to GitHub and "Fork" lockedata/sampleProject
  2. Go to your copy and copy the "Clone with SSH" URL
  3. Clone the repo using the cmd line

Adding an external source

  • Create new repository in GitHub
  • Get code for "existing repository"
  • Open shell
  • Copy & paste

Upload your code

  • Use the GUI to commit code
  • Hit Push!

Exercise

  1. Create repo online for one of your projects
  2. With your code all committed, add the online repo
  3. Upload your code

Checking for changes

Use the "pull" to get the latest copy of code online.

Exercises

  1. Pull the latest copy of your code

Good practices

Commit often

Keep changes as small as possible to avoid loss and more pain later.

Pull then Push

Before you push your changes always hit pull first!

Merge conflicts

Merge conflicts happen when multiple people have done something to the same lines at the same time and git doesn't know which one to pick.

Resolve by picking which bits you want. Commit and push!

<<<<<<< HEAD
I tried changing to this line
=======
And I tried changing to this line
>>>>>>> COMMITONREMOTE

to

And I tried changing to this line

Exercises

  • Alter a line on your README and commit it locally
  • Alter the same line differently online and commit it
  • Pull the changes
  • Fix the merge conflict in your text editor / R
  • Commit and push the fix
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment