Open Source Workflow

making changes when you don't have write access

My Repository

on

My GitHub

fork

make your own copy

Your copy of

My Repository

on Your GitHub

Your copy of

My Repository

on your local machine

clone

download your own copy

branch

make a parallel version

A parallel version of Your copy of

My Repository

on your local machine

Modify code

My Repository

on

My GitHub

pull request

ask to change my repository

Your copy of

My Repository

on Your GitHub

push

put changes

on your

GitHub

A parallel version of Your copy of

My Repository

on your local machine

Modify code

add

commit

record changes

merge

pull request

accept change

pull

sync

with

my

repo

My Repository

on

My GitHub

fork

make your own copy

Your copy of

My Repository

on Your GitHub

Your copy of

My Repository

on your local machine

clone

download your own copy

branch

make a parallel version

A parallel version of Your copy of

My Repository

on your local machine

Modify code

Exercise #1: fork my repo

  1. Go to: https://github.com/abostroem/code-review-2024-06-26-lsst.git
  2. Press the fork button
  1. Go to: https://github.com/abostroem/code_review-tau
  2.  
  3. Put your green sticky up when you're done

My Repository

on

My GitHub

fork

make your own copy

Your copy of

My Repository

on Your GitHub

Your copy of

My Repository

on your local machine

clone

download your own copy

branch

make a parallel version

A parallel version of Your copy of

My Repository

on your local machine

Modify code

Exercise #2: clone your copy of  my repo

this should be your GitHub username

  1. Copy url from green button
  2. Go to your shell window
  3. cd to your home directory
  4. git clone <paste url>
  5. Put up your green sticky when you're done

code-review-adass-2023

My Repository

on

My GitHub

fork

make your own copy

Your copy of

My Repository

on Your GitHub

Your copy of

My Repository

on your local machine

clone

download your own copy

branch

make a parallel version

A parallel version of Your copy of

My Repository

on your local machine

Modify code

Branching

Old way

doc1.py

doc1_v2.py

make a copy

Challenges:

  • Multiple copies
  • Making changes to both copies (e.g. bug fix)
  • what does v2 mean?
  • multiple files?

New way

doc1.py

new

branch

doc1.py

main

branch

doc1.py

doc1.py

doc1.py

New way

doc1.py

new

branch

doc1.py

master

branch

doc1.py

doc1.py

doc1.py

Advantages:

  • as many branches as you want
  • easy merging at any time (and any direction)
  • descriptive labeling

Branching

Branching: the mechanics

git branch <branch_name>
git checkout <branch_name>

git branch <branch_name>: create a new branch with name <branch_name>

 

git checkout <branch_name>: move to branch <branch_name>

 

git branch: list all branches

Branching: workflow

git branch feature
git checkout feature
git add
git commit
...
git checkout main
git merge feature

doc1.py

feature

branch

doc1.py

main

branch

doc1.py

doc1.py

doc1.py

Exercise #3: branching

Bonus:

  • commit to main
  • switch to your new branch
  • merge main into your new branch
  • make 2 commits
  • switch into main
  • merge your new branch into your main branch
git branch feature
git checkout feature
git add
git commit
...
git checkout main
git merge feature

Exercise #4:

  • In your code-review-2024-06-26-lsst directory create a new branch called refactor
  • Move to your new branch (git checkout)
  • Make one change to improve the code in make_plot.py
  • Record your changes (git add, git commit)
  • Move to the main branch (git checkout)
  • Merge your changes into main
  • Move back to your new branch

My Repository

on

My GitHub

pull request

ask to change my repository

Your copy of

My Repository

on Your GitHub

push

put changes

on your

GitHub

A parallel version of Your copy of

My Repository

on your local machine

Modify code

add

commit

record changes

merge

pull request

accept change

pull

sync

with

my

repo

My Repository

on

My GitHub

pull request

ask to change my repository

Your copy of

My Repository

on Your GitHub

push

put changes

on your

GitHub

A parallel version of Your copy of

My Repository

on your local machine

Modify code

add

commit

record changes

merge

pull request

accept change

pull

sync

with

my

repo

Update your remote copy

git push -u origin refactor

Exercise #5:

  • Go to your GitHub page
  • find the code-review-2024-06-26-lsst repository
  • check that your changes are there (you may need to reload)

Bonus:

  • Go to my GitHub page
  • find code-review-2024-06-26-lsst
  • check that your changes aren't there

My Repository

on

My GitHub

pull request

ask to change my repository

Your copy of

My Repository

on Your GitHub

push

put changes

on your

GitHub

A parallel version of Your copy of

My Repository

on your local machine

Modify code

add

commit

record changes

merge

pull request

accept change

pull

sync

with

my

repo

  1. Start Pull Request
  2. Check branch you want request change on (main)
  3. Check branch on which you made change (refactor)
  4. Create PR

Creating a Pull Request

main

...Azalee accepts PR...

My Repository

on

My GitHub

pull request

ask to change my repository

Your copy of

My Repository

on Your GitHub

push

put changes

on your

GitHub

A parallel version of Your copy of

My Repository

on your local machine

Modify code

add

commit

record changes

merge

pull request

accept change

pull

sync

with

my

repo

Incorporating Azalee's Changes

1. Add an alias for my repository

 

2. Check aliases

 

3. Check that you are on your refactor branch

 

 

4. Pull down changes from upstream repository*

git remote add upstream https://github.com/abostroem/code-review-2024-06-26-lsst
git remote -v
git branch
git checkout refactor
git pull upstream main

*you may need to resolve conflicts

History of Main Branch

original

changes from refactor branch

changes from Azalee's main branch

Exercise #6: Putting it all together

  1. create a new branch
  2. modify the code
  3. update new branch from upstream main
  4. resolve conflicts
  5. issue a pull request
git branch (<branch name>)
git checkout <branch name>
git add <filename>
git commit -m <message>
git pull <alias> <branch>
git push (-u) <alias> <branch>

Open Source Workflow

By abostroem

Open Source Workflow

  • 1,513