Collaborating using github

Remote repository

  • central location everyone can see
  • requires internet
  • github, bitbucket, gitlab
  • public vs private

Getting Ready

  • go to github.com
  • sign into your account
  • In your terminal, make sure that you are in your toy_repo directory
  • Click your "yes" button when you're done

Create a new repository

  • Press the + sign and select "New Repository
  • Call your repo toy_repo and "create repository"
  • Follow the directions to push an existing repository
  • click your "yes" button when you're finished
  • Copy and Paste this section into the terminal where you created your local repository
  • remote add... gives the nickname 'origin' to the url to the remote repository
  • git push -u ... creates remote branch on origin called master

Connect your remote and local repositories

Exercise: Explore your remote repository

  • at the top of the page click yourname/toy_repo

More information

  • what branch am I on?
    •  
    • default: master
  • what is my remote repository?
    •  
    • default nickname: origin
git branch
git remote -v

Collaborating with people you trust

  • write access to collaborators
  • simultaneously edit
  • merge changes

Merge #1

  • Your collaborator has modified the code but you have not
  1. Repositories are both up to date
  2. Dracula makes a change and pushes it to GitHub
  3. Wolfman pulls down Dracula's change before making any changes
  4. Wolfman will be asked to save a merge commit

GitHub

Merge #2

  • You and your collaborator modify different lines of code
  • Repositories are both up to date
  • Wolfman makes a change to the last line of a file and pushes it to GitHub
  • Dracula makes a change to the first line of the same file and tries to push it to GitHub (it fails)
  • Dracula Pulls down Wolfman's changes, merging the changes locally
  • Dracula will be asked to save a merge commit
  • Dracula pushes merged changes to GitHub

GitHub

Dracula's local repositorymatch GitHub

Wolfman's local repository

does not match GitHub

Merge #3

  • You and your collaborator modify the same line(s) of code
  • Wolfman and Dracula both modify the last line of the file
  • Wolfman pushes changes to GitHub
  • Dracula commits changes and then pulls down Wolfman's changes
  • Merge conflict

GitHub

Dracula's local repositorymatch GitHub

Wolfman's local repository

does not match GitHub

Merge #3: conflict

  • You and your collaborator modify the same line(s) of code
  • Wolfman and Dracula both modify the last line of the file
  • Wolfman pushes changes to GitHub
  • Dracula commits changes and then pulls down Wolfman's changes
  • Merge conflict

Resolving Conflicts

  • Dracula: open readme.md
  • Dracula: edit readme.md to look like correct file
    • remove extra text
    • choose which lines you want to keep
    • Delete the <<<HEAD, =====, and >>> lines
  • Dracula: save, add, commit, push
  • Note: if you open this file in VS code, the git interface makes this really easy

Starting your collaboration

  • We will divide you into breakout rooms with a partner
  • Before you start, decide who will be Dracula and who will be Wolfman
  • Follow the directions on the slides exactly
  • Leave the breakout room if you need help, Professor Knox or myself will be checking in there 

Wolfman: Cloning a repository

  • cd out of toy_repo, create a new directory called toy_repo_collab, and cd into it
cd ../
mkdir toy_repo_collab
cd toy_repo_collab
  • Clone Dracula's repository
  •  
    • make sure its set to HTTPS
  • cd into the toy_repo directory you just downloaded
git clone https://github.com/...

Dracula: adding a collaborator

  • Anyone can clone only collaborators can write
  • Dracula only:
    • Click settings on the RHS
    • Click collaborators on the LHS
    • Add Wolfman's github username under collaborators

Wolfman: Accept Dracula's invitation

You should receive an email or notification on GitHub that you've been invited to join Dracula's repository. Accept this invitation

1. Dracula

  • modify readme.md
  • save your changes
  • add and commit your changes
  • push your changes to the remote repository

2. Wolfman

  • pull down your partner's changes
    •  
  • add a line to the end of the readme.md
  • save your changes
  • add and commit your changes
  • push your changes to the remote repository

Collaborating

git push origin master
git pull origin master

Merge without conflict

  • Dracula: modify the first line of readme.md, save, add, and commit
  • Wolfman: modify the last line of readme.md, save, add, and commit
  • Dracula: pull down changes from Wolfman
    • you will be asked to save a merge commit message in nano
      • ctl+x
  • Dracula: push your changes to the remote repository
  • Wolfman: pull down changes from Dracula and save the commit message
  • Wolfman: push your changes to the remote repository

Merge with conflicts

  • Dracula: Before you pull down Wolfman's changes, edit the last line of the readme.md, save, add, and commit
  • Dracula: try to pull down changes from the remote repository

Resolving Conflicts

  • Dracula: open readme.md
  • Dracula: edit readme.md to look like correct file
    • remove extra text
    • choose which lines you want to keep
    • Delete the <<<HEAD, =====, and >>> lines
  • Dracula: save, add, commit, push

Exercise: Repeat for Wolfman

  • Wolfman: pull down Dracula's changes
  • Dracula: change the first line of hello_world.py
  • Dracula: save, add, commit, push
  • Wolfman: change the first line of hello_world.py, add, commit
  • Wolfman: pull down Dracula's changes
    • you will get a conflict
    • open hello_world.py and edit to look like final version
    • save changes to hello_world.py
    • add, commit, push

Clone the course repository

  • cd to your home directory (cd ~) or where ever you would like to put the repository
  •  
git clone https://github.com/ucdavis/DS4S.git

git_collaborating_no_branch_DS4S

By abostroem

git_collaborating_no_branch_DS4S

Assumes branching hasn't been taught Updated to new look of github

  • 1,363