Top Banner
Git and GitHub CS50 Seminar Brian Yu
71

Git and GitHub - CS50cdn.cs50.net/2016/fall/seminars/github/github.pdf · git add -adds a file to "staging area" -tells git to include the file in the next revision

May 20, 2020

Download

Documents

dariahiddleston
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Git and GitHub - CS50cdn.cs50.net/2016/fall/seminars/github/github.pdf · git add <filename>-adds a file to "staging area" -tells git to include the file in the next revision

Git and GitHubCS50 Seminar

Brian Yu

Page 2: Git and GitHub - CS50cdn.cs50.net/2016/fall/seminars/github/github.pdf · git add <filename>-adds a file to "staging area" -tells git to include the file in the next revision

What is Git?

Page 3: Git and GitHub - CS50cdn.cs50.net/2016/fall/seminars/github/github.pdf · git add <filename>-adds a file to "staging area" -tells git to include the file in the next revision

int a = 1; int b = 2; int c = 3;

Create file

Keep track of changes to code.

Page 4: Git and GitHub - CS50cdn.cs50.net/2016/fall/seminars/github/github.pdf · git add <filename>-adds a file to "staging area" -tells git to include the file in the next revision

int a = 1; int b = 2; int c = 3;

int a = 1; int b = 2; int c = 3; int d = 4;

Create file Add a line

Keep track of changes to code.

Page 5: Git and GitHub - CS50cdn.cs50.net/2016/fall/seminars/github/github.pdf · git add <filename>-adds a file to "staging area" -tells git to include the file in the next revision

int a = 1; int b = 2; int c = 3;

int a = 1; int b = 2; int c = 3; int d = 4;

int a = 1; int c = 3; int d = 4;

Create file Add a line Remove a line

Keep track of changes to code.

Page 6: Git and GitHub - CS50cdn.cs50.net/2016/fall/seminars/github/github.pdf · git add <filename>-adds a file to "staging area" -tells git to include the file in the next revision

int b = 2; int c = 3;int b = 2; int c = 3;int b = 2; int c = 3;

Synchronizes code between different people.

Page 7: Git and GitHub - CS50cdn.cs50.net/2016/fall/seminars/github/github.pdf · git add <filename>-adds a file to "staging area" -tells git to include the file in the next revision

int b = 2; int c = 3;

int b = 2; int c = 3;

int b = 2; int c = 3;

Synchronizes code between different people.

Page 8: Git and GitHub - CS50cdn.cs50.net/2016/fall/seminars/github/github.pdf · git add <filename>-adds a file to "staging area" -tells git to include the file in the next revision

int b = 2; int c = 3;

int a = 1; int b = 2; int c = 3;

int b = 2; int c = 3; int d = 4;

int a = 1; int b = 2; int c = 3;

int b = 2; int c = 3; int d = 4;

Synchronizes code between different people.

Page 9: Git and GitHub - CS50cdn.cs50.net/2016/fall/seminars/github/github.pdf · git add <filename>-adds a file to "staging area" -tells git to include the file in the next revision

int b = 2; int c = 3; int d = 4;

int a = 1; int b = 2; int c = 3;

int a = 1; int b = 2; int c = 3; int d = 4;

int a = 1; int b = 2; int c = 3;

int b = 2; int c = 3; int d = 4;

int a = 1; int b = 2; int c = 3; int d = 4;

int a = 1; int b = 2; int c = 3; int d = 4;

Synchronizes code between different people.

Page 10: Git and GitHub - CS50cdn.cs50.net/2016/fall/seminars/github/github.pdf · git add <filename>-adds a file to "staging area" -tells git to include the file in the next revision

int b = 2; int c = 3; int d = 4;

int a = 1; int b = 2; int c = 3;

int a = 1; int b = 2; int c = 3; int d = 4;

int a = 1; int b = 2; int c = 3;

int b = 2; int c = 3; int d = 4;

int a = 1; int b = 2; int c = 3; int d = 4;

int a = 1; int b = 2; int c = 3; int d = 4;

Synchronizes code between different people.

Page 11: Git and GitHub - CS50cdn.cs50.net/2016/fall/seminars/github/github.pdf · git add <filename>-adds a file to "staging area" -tells git to include the file in the next revision

int a = 1; int b = 2; int c = 3; int d = 4;

int a = 1; int b = 2; int c = 3; int d = 4;

int a = 1; int b = 2; int c = 3;

Test changes to code without losing the original.

Page 12: Git and GitHub - CS50cdn.cs50.net/2016/fall/seminars/github/github.pdf · git add <filename>-adds a file to "staging area" -tells git to include the file in the next revision

int a = 1; int b = 2; int c = 3;

int a = 1; int b = 2; int c = 3; int d = 4;

int a = 1; int b = 2; int c = 3; int d = 4;

Test changes to code without losing the original.

Page 13: Git and GitHub - CS50cdn.cs50.net/2016/fall/seminars/github/github.pdf · git add <filename>-adds a file to "staging area" -tells git to include the file in the next revision

int a = 1; int b = 2; int c = 3;

int a = 1; int b = 2; int c = 3; int d = 4;

int a = 1; int b = 2; int c = 3; int d = 4;

Test changes to code without losing the original.

Page 14: Git and GitHub - CS50cdn.cs50.net/2016/fall/seminars/github/github.pdf · git add <filename>-adds a file to "staging area" -tells git to include the file in the next revision

int a = 1; int b = 2; int c = 3;

int a = 1; int b = 2; int c = 3; int d = 4;

int a = 1; int c = 3; int d = 4;

Create file Add a line Remove a line

Revert back to old versions of code.

Page 15: Git and GitHub - CS50cdn.cs50.net/2016/fall/seminars/github/github.pdf · git add <filename>-adds a file to "staging area" -tells git to include the file in the next revision

int a = 1; int b = 2; int c = 3;

int a = 1; int b = 2; int c = 3; int d = 4;

Create file Add a line

Revert back to old versions of code.

Page 16: Git and GitHub - CS50cdn.cs50.net/2016/fall/seminars/github/github.pdf · git add <filename>-adds a file to "staging area" -tells git to include the file in the next revision

What is Git?

• Keeps track of changes to code.

• Synchronizes code between different people.

• Test changes to code without losing the original.

• Revert back to old versions of code.

Page 17: Git and GitHub - CS50cdn.cs50.net/2016/fall/seminars/github/github.pdf · git add <filename>-adds a file to "staging area" -tells git to include the file in the next revision

git clone

Page 18: Git and GitHub - CS50cdn.cs50.net/2016/fall/seminars/github/github.pdf · git add <filename>-adds a file to "staging area" -tells git to include the file in the next revision

git clone <url>int b = 2; int c = 3; int d = 4;

int a = 1; int b = 2; int c = 3;

int a = 1; int b = 2; int c = 3; int d = 4;

int a = 1; int b = 2; int c = 3; int d = 4;

int a = 1; int b = 2; int c = 3; int d = 4;

int a = 1; int b = 2; int c = 3; int d = 4;- makes a copy of a repository

- stores it on your computer - a "fork" creates your own copy

of someone else's repository

Page 19: Git and GitHub - CS50cdn.cs50.net/2016/fall/seminars/github/github.pdf · git add <filename>-adds a file to "staging area" -tells git to include the file in the next revision

git clone <url>

- makes a copy of a repository - stores it on your computer - a "fork" creates your own copy

of someone else's repository

git clone <url>

int b = 2; int c = 3; int d = 4;

int a = 1; int b = 2; int c = 3;

int a = 1; int b = 2; int c = 3; int d = 4;

int a = 1; int b = 2; int c = 3; int d = 4;

int a = 1; int b = 2; int c = 3; int d = 4;

int a = 1; int b = 2; int c = 3; int d = 4;

Page 20: Git and GitHub - CS50cdn.cs50.net/2016/fall/seminars/github/github.pdf · git add <filename>-adds a file to "staging area" -tells git to include the file in the next revision

git clone <url>int b = 2; int c = 3; int d = 4;

int a = 1; int b = 2; int c = 3;

int a = 1; int b = 2; int c = 3; int d = 4;

int a = 1; int b = 2; int c = 3; int d = 4;

int a = 1; int b = 2; int c = 3; int d = 4;

int a = 1; int b = 2; int c = 3; int d = 4;

- makes a copy of a repository - stores it on your computer - a "fork" creates your own copy

of someone else's repository

git clone <url>

Page 21: Git and GitHub - CS50cdn.cs50.net/2016/fall/seminars/github/github.pdf · git add <filename>-adds a file to "staging area" -tells git to include the file in the next revision

git add

Page 22: Git and GitHub - CS50cdn.cs50.net/2016/fall/seminars/github/github.pdf · git add <filename>-adds a file to "staging area" -tells git to include the file in the next revision

git add <filename>int b = 2; int c = 3; int d = 4;

int a = 1; int b = 2; int c = 3;

int a = 1; int b = 2; int c = 3; int d = 4;

int a = 1; int b = 2; int c = 3; int d = 4;

int a = 1; int b = 2; int c = 3; int d = 4;

int a = 1; int b = 2; int c = 3; int d = 4;

- adds a file to "staging area" - tells git to include the file

in the next revision to the repository - git add * adds all changed files

Page 23: Git and GitHub - CS50cdn.cs50.net/2016/fall/seminars/github/github.pdf · git add <filename>-adds a file to "staging area" -tells git to include the file in the next revision

git add <filename>int b = 2; int c = 3; int d = 4;

int a = 1; int b = 2; int c = 3;

int a = 1; int b = 2; int c = 3; int d = 4;

int a = 1; int b = 2; int c = 3; int d = 4;

int a = 1; int b = 2; int c = 3; int d = 4;

int a = 1; int b = 2; int c = 3; int d = 4; int e = 5;

- adds a file to "staging area" - tells git to include the file

in the next revision to the repository - git add * adds all changed files

Page 24: Git and GitHub - CS50cdn.cs50.net/2016/fall/seminars/github/github.pdf · git add <filename>-adds a file to "staging area" -tells git to include the file in the next revision

git add <filename>

- adds a file to "staging area" - tells git to include the file

in the next revision to the repository - git add * adds all changed files

git add foo.c

int a = 1; int b = 2; int c = 3; int d = 4; int e = 5;

int b = 2; int c = 3; int d = 4;

int a = 1; int b = 2; int c = 3;

int a = 1; int b = 2; int c = 3; int d = 4;

int a = 1; int b = 2; int c = 3; int d = 4;

int a = 1; int b = 2; int c = 3; int d = 4;

Page 25: Git and GitHub - CS50cdn.cs50.net/2016/fall/seminars/github/github.pdf · git add <filename>-adds a file to "staging area" -tells git to include the file in the next revision

git add <filename>

- adds a file to "staging area" - tells git to include the file

in the next revision to the repository - git add * adds all changed files

Changes to be committed:

modified: foo.c

git add foo.c

int a = 1; int b = 2; int c = 3; int d = 4; int e = 5;

int b = 2; int c = 3; int d = 4;

int a = 1; int b = 2; int c = 3;

int a = 1; int b = 2; int c = 3; int d = 4;

int a = 1; int b = 2; int c = 3; int d = 4;

int a = 1; int b = 2; int c = 3; int d = 4;

Page 26: Git and GitHub - CS50cdn.cs50.net/2016/fall/seminars/github/github.pdf · git add <filename>-adds a file to "staging area" -tells git to include the file in the next revision

git commit

Page 27: Git and GitHub - CS50cdn.cs50.net/2016/fall/seminars/github/github.pdf · git add <filename>-adds a file to "staging area" -tells git to include the file in the next revision

int a = 1; int b = 2; int c = 3; int d = 4;

git commit -m "message"int b = 2; int c = 3; int d = 4;

int a = 1; int b = 2; int c = 3;

int a = 1; int b = 2; int c = 3; int d = 4;

int a = 1; int b = 2; int c = 3; int d = 4;

int a = 1; int b = 2; int c = 3; int d = 4;

int a = 1; int b = 2; int c = 3; int d = 4; int e = 5;

- saves the changes to repository asa new revision (a "commit")

- records a message - git commit -am "message" adds

and commits in same step

Page 28: Git and GitHub - CS50cdn.cs50.net/2016/fall/seminars/github/github.pdf · git add <filename>-adds a file to "staging area" -tells git to include the file in the next revision

git commit -m "message"

- saves the changes to repository asa new revision (a "commit")

- records a message - git commit -am "message" adds

and commits in same step

git commit -m "Add line"

int b = 2; int c = 3; int d = 4;

int a = 1; int b = 2; int c = 3;

int a = 1; int b = 2; int c = 3; int d = 4;

int a = 1; int b = 2; int c = 3; int d = 4;

int a = 1; int b = 2; int c = 3; int d = 4;

int a = 1; int b = 2; int c = 3; int d = 4;

int a = 1; int b = 2; int c = 3; int d = 4; int e = 5;

Page 29: Git and GitHub - CS50cdn.cs50.net/2016/fall/seminars/github/github.pdf · git add <filename>-adds a file to "staging area" -tells git to include the file in the next revision

git commit -m "message"

- saves the changes to repository asa new revision (a "commit")

- records a message - git commit -am "message" adds

and commits in same step

git commit -m "Add line"

int a = 1; int b = 2; int c = 3; int d = 4;

Add line

int b = 2; int c = 3; int d = 4;

int a = 1; int b = 2; int c = 3;

int a = 1; int b = 2; int c = 3; int d = 4;

int a = 1; int b = 2; int c = 3; int d = 4;

int a = 1; int b = 2; int c = 3; int d = 4;

int a = 1; int b = 2; int c = 3; int d = 4; int e = 5;

Page 30: Git and GitHub - CS50cdn.cs50.net/2016/fall/seminars/github/github.pdf · git add <filename>-adds a file to "staging area" -tells git to include the file in the next revision

git status

Page 31: Git and GitHub - CS50cdn.cs50.net/2016/fall/seminars/github/github.pdf · git add <filename>-adds a file to "staging area" -tells git to include the file in the next revision

git status

- shows current status of repository

Add line

int b = 2; int c = 3; int d = 4;

int a = 1; int b = 2; int c = 3;

int a = 1; int b = 2; int c = 3; int d = 4;

int a = 1; int b = 2; int c = 3; int d = 4;

int a = 1; int b = 2; int c = 3; int d = 4;

int a = 1; int b = 2; int c = 3; int d = 4; int e = 5;

int a = 1; int b = 2; int c = 3; int d = 4;

Page 32: Git and GitHub - CS50cdn.cs50.net/2016/fall/seminars/github/github.pdf · git add <filename>-adds a file to "staging area" -tells git to include the file in the next revision

git status

- shows current status of repository

git status Add line

int b = 2; int c = 3; int d = 4;

int a = 1; int b = 2; int c = 3;

int a = 1; int b = 2; int c = 3; int d = 4;

int a = 1; int b = 2; int c = 3; int d = 4;

int a = 1; int b = 2; int c = 3; int d = 4;

int a = 1; int b = 2; int c = 3; int d = 4; int e = 5;

int a = 1; int b = 2; int c = 3; int d = 4;

Page 33: Git and GitHub - CS50cdn.cs50.net/2016/fall/seminars/github/github.pdf · git add <filename>-adds a file to "staging area" -tells git to include the file in the next revision

git status

int a = 1; int b = 2; int c = 3; int d = 4; int e = 5;

- shows current status of repository

git status

int a = 1; int b = 2; int c = 3; int d = 4;

Add line

On branch master Your branch is ahead of 'origin/master' by 1 commit. (use "git push" to publish your local commits)

int b = 2; int c = 3; int d = 4;

int a = 1; int b = 2; int c = 3;

int a = 1; int b = 2; int c = 3; int d = 4;

int a = 1; int b = 2; int c = 3; int d = 4;

int a = 1; int b = 2; int c = 3; int d = 4;

Page 34: Git and GitHub - CS50cdn.cs50.net/2016/fall/seminars/github/github.pdf · git add <filename>-adds a file to "staging area" -tells git to include the file in the next revision

git push

Page 35: Git and GitHub - CS50cdn.cs50.net/2016/fall/seminars/github/github.pdf · git add <filename>-adds a file to "staging area" -tells git to include the file in the next revision

git pushint a = 1; int b = 2; int c = 3; int d = 4;

int b = 2; int c = 3; int d = 4;

int a = 1; int b = 2; int c = 3;

int a = 1; int b = 2; int c = 3; int d = 4;

int a = 1; int b = 2; int c = 3; int d = 4;

int a = 1; int b = 2; int c = 3; int d = 4; int e = 5;

- sends committed changes toremote repository

- more explicitly, could writegit push origin master

Add line

int a = 1; int b = 2; int c = 3; int d = 4; int e = 5;

Add line

int a = 1; int b = 2; int c = 3; int d = 4;

Page 36: Git and GitHub - CS50cdn.cs50.net/2016/fall/seminars/github/github.pdf · git add <filename>-adds a file to "staging area" -tells git to include the file in the next revision

git pushint a = 1; int b = 2; int c = 3; int d = 4;

int b = 2; int c = 3; int d = 4;

int a = 1; int b = 2; int c = 3;

int a = 1; int b = 2; int c = 3; int d = 4;

int a = 1; int b = 2; int c = 3; int d = 4;

int a = 1; int b = 2; int c = 3; int d = 4; int e = 5;

- sends committed changes toremote repository

- more explicitly, could writegit push origin master

git push

Add line

int a = 1; int b = 2; int c = 3; int d = 4; int e = 5;

Add line

int a = 1; int b = 2; int c = 3; int d = 4;

Page 37: Git and GitHub - CS50cdn.cs50.net/2016/fall/seminars/github/github.pdf · git add <filename>-adds a file to "staging area" -tells git to include the file in the next revision

git pushint a = 1; int b = 2; int c = 3; int d = 4;

int b = 2; int c = 3; int d = 4;

int a = 1; int b = 2; int c = 3;

int a = 1; int b = 2; int c = 3; int d = 4;

int a = 1; int b = 2; int c = 3; int d = 4; int e = 5;

- sends committed changes toremote repository

- more explicitly, could writegit push origin master

git push

Add line

int a = 1; int b = 2; int c = 3; int d = 4; int e = 5;

Add line

int a = 1; int b = 2; int c = 3; int d = 4;

int a = 1; int b = 2; int c = 3; int d = 4;

Page 38: Git and GitHub - CS50cdn.cs50.net/2016/fall/seminars/github/github.pdf · git add <filename>-adds a file to "staging area" -tells git to include the file in the next revision

git pull

Page 39: Git and GitHub - CS50cdn.cs50.net/2016/fall/seminars/github/github.pdf · git add <filename>-adds a file to "staging area" -tells git to include the file in the next revision

git pull

int a = 1; int b = 2; int c = 3; int d = 4; int e = 5;

- retrieves changes fromremote repository

Add line

int a = 1; int b = 2; int c = 3; int d = 4; int e = 5;

Add line

int a = 1; int b = 2; int c = 3; int d = 4;

int a = 1; int b = 2; int c = 3; int d = 4;

int a = 1; int c = 3; int d = 4; int e = 5;

Remove line

int a = 1; int c = 3; int d = 4; int e = 5;

Remove line

Page 40: Git and GitHub - CS50cdn.cs50.net/2016/fall/seminars/github/github.pdf · git add <filename>-adds a file to "staging area" -tells git to include the file in the next revision

git pull

- retrieves changes fromremote repository

git pull

Add line

Add line

int a = 1; int c = 3; int d = 4; int e = 5;

Remove line

int a = 1; int c = 3; int d = 4; int e = 5;

Remove line

int a = 1; int b = 2; int c = 3; int d = 4;

int a = 1; int b = 2; int c = 3; int d = 4; int e = 5;

int a = 1; int b = 2; int c = 3; int d = 4;

int a = 1; int b = 2; int c = 3; int d = 4; int e = 5;

Page 41: Git and GitHub - CS50cdn.cs50.net/2016/fall/seminars/github/github.pdf · git add <filename>-adds a file to "staging area" -tells git to include the file in the next revision

git pull

- retrieves changes fromremote repository

git pull

Add line

Add line

int a = 1; int c = 3; int d = 4; int e = 5;

Remove line

int a = 1; int c = 3; int d = 4; int e = 5;

Remove line

int a = 1; int b = 2; int c = 3; int d = 4;

int a = 1; int b = 2; int c = 3; int d = 4; int e = 5;

int a = 1; int b = 2; int c = 3; int d = 4; int e = 5;

int a = 1; int b = 2; int c = 3; int d = 4;

Page 42: Git and GitHub - CS50cdn.cs50.net/2016/fall/seminars/github/github.pdf · git add <filename>-adds a file to "staging area" -tells git to include the file in the next revision

Merge Conflicts

Page 43: Git and GitHub - CS50cdn.cs50.net/2016/fall/seminars/github/github.pdf · git add <filename>-adds a file to "staging area" -tells git to include the file in the next revision

Merge Conflicts- when two different commits

can't be automatically merged - need to be resolved

Page 44: Git and GitHub - CS50cdn.cs50.net/2016/fall/seminars/github/github.pdf · git add <filename>-adds a file to "staging area" -tells git to include the file in the next revision

Merge Conflicts- when two different commits

can't be automatically merged - need to be resolved

git pull

Page 45: Git and GitHub - CS50cdn.cs50.net/2016/fall/seminars/github/github.pdf · git add <filename>-adds a file to "staging area" -tells git to include the file in the next revision

Merge Conflicts- when two different commits

can't be automatically merged - need to be resolved

git pullCONFLICT (content): Merge conflict in foo.c Automatic merge failed; fix conflicts and then commit the result.

Page 46: Git and GitHub - CS50cdn.cs50.net/2016/fall/seminars/github/github.pdf · git add <filename>-adds a file to "staging area" -tells git to include the file in the next revision

Merge Conflicts- when two different commits

can't be automatically merged - need to be resolved

git pull

int a = 1; <<<<<<< HEAD int b = 2; ======= int b = 0; >>>>>>> 5468697320697320435335302e int c = 3; int d = 4; int e = 5;

foo.c

Page 47: Git and GitHub - CS50cdn.cs50.net/2016/fall/seminars/github/github.pdf · git add <filename>-adds a file to "staging area" -tells git to include the file in the next revision

Merge Conflicts- when two different commits

can't be automatically merged - need to be resolved

git pull

int a = 1; <<<<<<< HEAD int b = 2; ======= int b = 0; >>>>>>> 5468697320697320435335302e int c = 3; int d = 4; int e = 5;

foo.c

your changes

remote changes

conflicting commit{{

Page 48: Git and GitHub - CS50cdn.cs50.net/2016/fall/seminars/github/github.pdf · git add <filename>-adds a file to "staging area" -tells git to include the file in the next revision

Merge Conflicts- when two different commits

can't be automatically merged - need to be resolved

git pull

int a = 1; <<<<<<< HEAD int b = 2; ======= int b = 0; >>>>>>> 5468697320697320435335302e int c = 3; int d = 4; int e = 5;

foo.c

Page 49: Git and GitHub - CS50cdn.cs50.net/2016/fall/seminars/github/github.pdf · git add <filename>-adds a file to "staging area" -tells git to include the file in the next revision

Merge Conflicts- when two different commits

can't be automatically merged - need to be resolved

git pull

int a = 1;

int b = 2;

int c = 3; int d = 4; int e = 5;

foo.c

Page 50: Git and GitHub - CS50cdn.cs50.net/2016/fall/seminars/github/github.pdf · git add <filename>-adds a file to "staging area" -tells git to include the file in the next revision

Merge Conflicts- when two different commits

can't be automatically merged - need to be resolved

git pull

int a = 1; int b = 2; int c = 3; int d = 4; int e = 5;

foo.c

Page 51: Git and GitHub - CS50cdn.cs50.net/2016/fall/seminars/github/github.pdf · git add <filename>-adds a file to "staging area" -tells git to include the file in the next revision

git log

Page 52: Git and GitHub - CS50cdn.cs50.net/2016/fall/seminars/github/github.pdf · git add <filename>-adds a file to "staging area" -tells git to include the file in the next revision

git log

- shows a history ofcommits and messages

Page 53: Git and GitHub - CS50cdn.cs50.net/2016/fall/seminars/github/github.pdf · git add <filename>-adds a file to "staging area" -tells git to include the file in the next revision

git log

- shows a history ofcommits and messages

git log

Page 54: Git and GitHub - CS50cdn.cs50.net/2016/fall/seminars/github/github.pdf · git add <filename>-adds a file to "staging area" -tells git to include the file in the next revision

git log

- shows a history ofcommits and messages

git log

commit 5468697320697320435335302e Author: Brian Yu <[email protected]> Date: Tue Oct 11 21:09:37 2016 -0400

Remove a line

commit 4920746f6f6b20435335302e Author: Brian Yu <[email protected]> Date: Tue Oct 11 21:05:28 2016 -0400

Add a line

Page 55: Git and GitHub - CS50cdn.cs50.net/2016/fall/seminars/github/github.pdf · git add <filename>-adds a file to "staging area" -tells git to include the file in the next revision

git reset

Page 56: Git and GitHub - CS50cdn.cs50.net/2016/fall/seminars/github/github.pdf · git add <filename>-adds a file to "staging area" -tells git to include the file in the next revision

git reset

int a = 1; int b = 2; int c = 3; int d = 4; int e = 5;

- git reset --hard <commit>reverts code back to a previous commit

- git reset --hard origin/masterreverts code back to remote repository version

Add line

int a = 1; int b = 2; int c = 3; int d = 4;

int a = 1; int c = 3; int d = 4; int e = 5;

Remove line4761626 53616d2

Page 57: Git and GitHub - CS50cdn.cs50.net/2016/fall/seminars/github/github.pdf · git add <filename>-adds a file to "staging area" -tells git to include the file in the next revision

git reset

int a = 1; int b = 2; int c = 3; int d = 4; int e = 5;

Add line

int a = 1; int b = 2; int c = 3; int d = 4;

int a = 1; int c = 3; int d = 4; int e = 5;

Remove line

git reset --hard 4761626

- git reset --hard <commit>reverts code back to a previous commit

- git reset --hard origin/masterreverts code back to remote repository version

4761626 53616d2

Page 58: Git and GitHub - CS50cdn.cs50.net/2016/fall/seminars/github/github.pdf · git add <filename>-adds a file to "staging area" -tells git to include the file in the next revision

git reset

int a = 1; int b = 2; int c = 3; int d = 4; int e = 5;

git reset --hard 4761626

Add line

int a = 1; int b = 2; int c = 3; int d = 4;

- git reset --hard <commit>reverts code back to a previous commit

- git reset --hard origin/masterreverts code back to remote repository version

4761626

Page 59: Git and GitHub - CS50cdn.cs50.net/2016/fall/seminars/github/github.pdf · git add <filename>-adds a file to "staging area" -tells git to include the file in the next revision

Branching

Page 60: Git and GitHub - CS50cdn.cs50.net/2016/fall/seminars/github/github.pdf · git add <filename>-adds a file to "staging area" -tells git to include the file in the next revision

Branching

• Branch is a version of the repository.

• Each branch has its own commit history and current version.

Page 61: Git and GitHub - CS50cdn.cs50.net/2016/fall/seminars/github/github.pdf · git add <filename>-adds a file to "staging area" -tells git to include the file in the next revision

git branch

Page 62: Git and GitHub - CS50cdn.cs50.net/2016/fall/seminars/github/github.pdf · git add <filename>-adds a file to "staging area" -tells git to include the file in the next revision

git branch

int a = 1; int b = 2; int c = 3; int d = 4;

- shows all branches of code - create a branch with git branch <branch_name> - switch to ("checkout") a new branch

with git checkout <branch_name>

master

int a = 1; int b = 2; int c = 3; int d = 4;

Page 63: Git and GitHub - CS50cdn.cs50.net/2016/fall/seminars/github/github.pdf · git add <filename>-adds a file to "staging area" -tells git to include the file in the next revision

git branch

git branch tests

int a = 1; int b = 2; int c = 3; int d = 4;

- shows all branches of code - create a branch with git branch <branch_name> - switch to ("checkout") a new branch

with git checkout <branch_name>

master

int a = 1; int b = 2; int c = 3; int d = 4;

Page 64: Git and GitHub - CS50cdn.cs50.net/2016/fall/seminars/github/github.pdf · git add <filename>-adds a file to "staging area" -tells git to include the file in the next revision

git branch

git branch tests

int a = 1; int b = 2; int c = 3; int d = 4;

- shows all branches of code - create a branch with git branch <branch_name> - switch to ("checkout") a new branch

with git checkout <branch_name>

master

int a = 1; int b = 2; int c = 3; int d = 4;

tests

Page 65: Git and GitHub - CS50cdn.cs50.net/2016/fall/seminars/github/github.pdf · git add <filename>-adds a file to "staging area" -tells git to include the file in the next revision

git merge

Page 66: Git and GitHub - CS50cdn.cs50.net/2016/fall/seminars/github/github.pdf · git add <filename>-adds a file to "staging area" -tells git to include the file in the next revision

let a = 0;; int b = 2; int c = 3; int d = 4; int e = 5;

git merge

int a = 1; int b = 2; int c = 3; int d = 4;

- git merge <branch_name> merges the branch branch_name with current branch

master

int a = 1; int b = 2; int c = 3; int d = 4;

testsint a = 1; int b = 2; int c = 3; int d = 4; int e = 5;

let a = 0;; int b = 2; int c = 3; int d = 4; int e = 5;

int a = 1; int b = 2; int c = 3; int d = 4; int e = 5;

Page 67: Git and GitHub - CS50cdn.cs50.net/2016/fall/seminars/github/github.pdf · git add <filename>-adds a file to "staging area" -tells git to include the file in the next revision

let a = 0;; int b = 2; int c = 3; int d = 4; int e = 5;

git merge

git merge tests

int a = 1; int b = 2; int c = 3; int d = 4;

- git merge <branch_name> merges the branch branch_name with current branch

master

int a = 1; int b = 2; int c = 3; int d = 4;

testsint a = 1; int b = 2; int c = 3; int d = 4; int e = 5;

let a = 0;; int b = 2; int c = 3; int d = 4; int e = 5;

int a = 1; int b = 2; int c = 3; int d = 4; int e = 5;

Page 68: Git and GitHub - CS50cdn.cs50.net/2016/fall/seminars/github/github.pdf · git add <filename>-adds a file to "staging area" -tells git to include the file in the next revision

let a = 0;; int b = 2; int c = 3; int d = 4; int e = 5;

git merge

git merge tests

int a = 1; int b = 2; int c = 3; int d = 4;

- git merge <branch_name> merges the branch branch_name with current branch

master

int a = 1; int b = 2; int c = 3; int d = 4;

testsint a = 1; int b = 2; int c = 3; int d = 4; int e = 5;

let a = 0;; int b = 2; int c = 3; int d = 4; int e = 5;

int a = 1; int b = 2; int c = 3; int d = 4; int e = 5;

Page 69: Git and GitHub - CS50cdn.cs50.net/2016/fall/seminars/github/github.pdf · git add <filename>-adds a file to "staging area" -tells git to include the file in the next revision

Pull Requests

Page 70: Git and GitHub - CS50cdn.cs50.net/2016/fall/seminars/github/github.pdf · git add <filename>-adds a file to "staging area" -tells git to include the file in the next revision

Git

• Keeps track of changes to code.

• Synchronizes code between different people.

• Test changes to code without losing the original.

• Revert back to old versions of code.

Page 71: Git and GitHub - CS50cdn.cs50.net/2016/fall/seminars/github/github.pdf · git add <filename>-adds a file to "staging area" -tells git to include the file in the next revision

Git and GitHubCS50 Seminar

Brian Yu