![Page 1: 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](https://reader030.vdocuments.us/reader030/viewer/2022040204/5ec60176f5348049da032703/html5/thumbnails/1.jpg)
Git and GitHubCS50 Seminar
Brian Yu
![Page 2: 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](https://reader030.vdocuments.us/reader030/viewer/2022040204/5ec60176f5348049da032703/html5/thumbnails/2.jpg)
What is Git?
![Page 3: 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](https://reader030.vdocuments.us/reader030/viewer/2022040204/5ec60176f5348049da032703/html5/thumbnails/3.jpg)
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 -adds a file to "staging area" -tells git to include the file in the next revision](https://reader030.vdocuments.us/reader030/viewer/2022040204/5ec60176f5348049da032703/html5/thumbnails/4.jpg)
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 -adds a file to "staging area" -tells git to include the file in the next revision](https://reader030.vdocuments.us/reader030/viewer/2022040204/5ec60176f5348049da032703/html5/thumbnails/5.jpg)
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 -adds a file to "staging area" -tells git to include the file in the next revision](https://reader030.vdocuments.us/reader030/viewer/2022040204/5ec60176f5348049da032703/html5/thumbnails/6.jpg)
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 -adds a file to "staging area" -tells git to include the file in the next revision](https://reader030.vdocuments.us/reader030/viewer/2022040204/5ec60176f5348049da032703/html5/thumbnails/7.jpg)
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 -adds a file to "staging area" -tells git to include the file in the next revision](https://reader030.vdocuments.us/reader030/viewer/2022040204/5ec60176f5348049da032703/html5/thumbnails/8.jpg)
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 -adds a file to "staging area" -tells git to include the file in the next revision](https://reader030.vdocuments.us/reader030/viewer/2022040204/5ec60176f5348049da032703/html5/thumbnails/9.jpg)
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 -adds a file to "staging area" -tells git to include the file in the next revision](https://reader030.vdocuments.us/reader030/viewer/2022040204/5ec60176f5348049da032703/html5/thumbnails/10.jpg)
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 -adds a file to "staging area" -tells git to include the file in the next revision](https://reader030.vdocuments.us/reader030/viewer/2022040204/5ec60176f5348049da032703/html5/thumbnails/11.jpg)
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 -adds a file to "staging area" -tells git to include the file in the next revision](https://reader030.vdocuments.us/reader030/viewer/2022040204/5ec60176f5348049da032703/html5/thumbnails/12.jpg)
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 -adds a file to "staging area" -tells git to include the file in the next revision](https://reader030.vdocuments.us/reader030/viewer/2022040204/5ec60176f5348049da032703/html5/thumbnails/13.jpg)
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 -adds a file to "staging area" -tells git to include the file in the next revision](https://reader030.vdocuments.us/reader030/viewer/2022040204/5ec60176f5348049da032703/html5/thumbnails/14.jpg)
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 -adds a file to "staging area" -tells git to include the file in the next revision](https://reader030.vdocuments.us/reader030/viewer/2022040204/5ec60176f5348049da032703/html5/thumbnails/15.jpg)
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 -adds a file to "staging area" -tells git to include the file in the next revision](https://reader030.vdocuments.us/reader030/viewer/2022040204/5ec60176f5348049da032703/html5/thumbnails/16.jpg)
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 -adds a file to "staging area" -tells git to include the file in the next revision](https://reader030.vdocuments.us/reader030/viewer/2022040204/5ec60176f5348049da032703/html5/thumbnails/17.jpg)
git clone
![Page 18: 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](https://reader030.vdocuments.us/reader030/viewer/2022040204/5ec60176f5348049da032703/html5/thumbnails/18.jpg)
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 -adds a file to "staging area" -tells git to include the file in the next revision](https://reader030.vdocuments.us/reader030/viewer/2022040204/5ec60176f5348049da032703/html5/thumbnails/19.jpg)
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 -adds a file to "staging area" -tells git to include the file in the next revision](https://reader030.vdocuments.us/reader030/viewer/2022040204/5ec60176f5348049da032703/html5/thumbnails/20.jpg)
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 -adds a file to "staging area" -tells git to include the file in the next revision](https://reader030.vdocuments.us/reader030/viewer/2022040204/5ec60176f5348049da032703/html5/thumbnails/21.jpg)
git add
![Page 22: 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](https://reader030.vdocuments.us/reader030/viewer/2022040204/5ec60176f5348049da032703/html5/thumbnails/22.jpg)
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 -adds a file to "staging area" -tells git to include the file in the next revision](https://reader030.vdocuments.us/reader030/viewer/2022040204/5ec60176f5348049da032703/html5/thumbnails/23.jpg)
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 -adds a file to "staging area" -tells git to include the file in the next revision](https://reader030.vdocuments.us/reader030/viewer/2022040204/5ec60176f5348049da032703/html5/thumbnails/24.jpg)
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 -adds a file to "staging area" -tells git to include the file in the next revision](https://reader030.vdocuments.us/reader030/viewer/2022040204/5ec60176f5348049da032703/html5/thumbnails/25.jpg)
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 -adds a file to "staging area" -tells git to include the file in the next revision](https://reader030.vdocuments.us/reader030/viewer/2022040204/5ec60176f5348049da032703/html5/thumbnails/26.jpg)
git commit
![Page 27: 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](https://reader030.vdocuments.us/reader030/viewer/2022040204/5ec60176f5348049da032703/html5/thumbnails/27.jpg)
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 -adds a file to "staging area" -tells git to include the file in the next revision](https://reader030.vdocuments.us/reader030/viewer/2022040204/5ec60176f5348049da032703/html5/thumbnails/28.jpg)
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 -adds a file to "staging area" -tells git to include the file in the next revision](https://reader030.vdocuments.us/reader030/viewer/2022040204/5ec60176f5348049da032703/html5/thumbnails/29.jpg)
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 -adds a file to "staging area" -tells git to include the file in the next revision](https://reader030.vdocuments.us/reader030/viewer/2022040204/5ec60176f5348049da032703/html5/thumbnails/30.jpg)
git status
![Page 31: 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](https://reader030.vdocuments.us/reader030/viewer/2022040204/5ec60176f5348049da032703/html5/thumbnails/31.jpg)
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 -adds a file to "staging area" -tells git to include the file in the next revision](https://reader030.vdocuments.us/reader030/viewer/2022040204/5ec60176f5348049da032703/html5/thumbnails/32.jpg)
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 -adds a file to "staging area" -tells git to include the file in the next revision](https://reader030.vdocuments.us/reader030/viewer/2022040204/5ec60176f5348049da032703/html5/thumbnails/33.jpg)
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 -adds a file to "staging area" -tells git to include the file in the next revision](https://reader030.vdocuments.us/reader030/viewer/2022040204/5ec60176f5348049da032703/html5/thumbnails/34.jpg)
git push
![Page 35: 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](https://reader030.vdocuments.us/reader030/viewer/2022040204/5ec60176f5348049da032703/html5/thumbnails/35.jpg)
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 -adds a file to "staging area" -tells git to include the file in the next revision](https://reader030.vdocuments.us/reader030/viewer/2022040204/5ec60176f5348049da032703/html5/thumbnails/36.jpg)
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 -adds a file to "staging area" -tells git to include the file in the next revision](https://reader030.vdocuments.us/reader030/viewer/2022040204/5ec60176f5348049da032703/html5/thumbnails/37.jpg)
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 -adds a file to "staging area" -tells git to include the file in the next revision](https://reader030.vdocuments.us/reader030/viewer/2022040204/5ec60176f5348049da032703/html5/thumbnails/38.jpg)
git pull
![Page 39: 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](https://reader030.vdocuments.us/reader030/viewer/2022040204/5ec60176f5348049da032703/html5/thumbnails/39.jpg)
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 -adds a file to "staging area" -tells git to include the file in the next revision](https://reader030.vdocuments.us/reader030/viewer/2022040204/5ec60176f5348049da032703/html5/thumbnails/40.jpg)
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 -adds a file to "staging area" -tells git to include the file in the next revision](https://reader030.vdocuments.us/reader030/viewer/2022040204/5ec60176f5348049da032703/html5/thumbnails/41.jpg)
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 -adds a file to "staging area" -tells git to include the file in the next revision](https://reader030.vdocuments.us/reader030/viewer/2022040204/5ec60176f5348049da032703/html5/thumbnails/42.jpg)
Merge Conflicts
![Page 43: 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](https://reader030.vdocuments.us/reader030/viewer/2022040204/5ec60176f5348049da032703/html5/thumbnails/43.jpg)
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 -adds a file to "staging area" -tells git to include the file in the next revision](https://reader030.vdocuments.us/reader030/viewer/2022040204/5ec60176f5348049da032703/html5/thumbnails/44.jpg)
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 -adds a file to "staging area" -tells git to include the file in the next revision](https://reader030.vdocuments.us/reader030/viewer/2022040204/5ec60176f5348049da032703/html5/thumbnails/45.jpg)
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 -adds a file to "staging area" -tells git to include the file in the next revision](https://reader030.vdocuments.us/reader030/viewer/2022040204/5ec60176f5348049da032703/html5/thumbnails/46.jpg)
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 -adds a file to "staging area" -tells git to include the file in the next revision](https://reader030.vdocuments.us/reader030/viewer/2022040204/5ec60176f5348049da032703/html5/thumbnails/47.jpg)
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 -adds a file to "staging area" -tells git to include the file in the next revision](https://reader030.vdocuments.us/reader030/viewer/2022040204/5ec60176f5348049da032703/html5/thumbnails/48.jpg)
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 -adds a file to "staging area" -tells git to include the file in the next revision](https://reader030.vdocuments.us/reader030/viewer/2022040204/5ec60176f5348049da032703/html5/thumbnails/49.jpg)
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 -adds a file to "staging area" -tells git to include the file in the next revision](https://reader030.vdocuments.us/reader030/viewer/2022040204/5ec60176f5348049da032703/html5/thumbnails/50.jpg)
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 -adds a file to "staging area" -tells git to include the file in the next revision](https://reader030.vdocuments.us/reader030/viewer/2022040204/5ec60176f5348049da032703/html5/thumbnails/51.jpg)
git log
![Page 52: 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](https://reader030.vdocuments.us/reader030/viewer/2022040204/5ec60176f5348049da032703/html5/thumbnails/52.jpg)
git log
- shows a history ofcommits and messages
![Page 53: 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](https://reader030.vdocuments.us/reader030/viewer/2022040204/5ec60176f5348049da032703/html5/thumbnails/53.jpg)
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 -adds a file to "staging area" -tells git to include the file in the next revision](https://reader030.vdocuments.us/reader030/viewer/2022040204/5ec60176f5348049da032703/html5/thumbnails/54.jpg)
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 -adds a file to "staging area" -tells git to include the file in the next revision](https://reader030.vdocuments.us/reader030/viewer/2022040204/5ec60176f5348049da032703/html5/thumbnails/55.jpg)
git reset
![Page 56: 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](https://reader030.vdocuments.us/reader030/viewer/2022040204/5ec60176f5348049da032703/html5/thumbnails/56.jpg)
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 -adds a file to "staging area" -tells git to include the file in the next revision](https://reader030.vdocuments.us/reader030/viewer/2022040204/5ec60176f5348049da032703/html5/thumbnails/57.jpg)
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 -adds a file to "staging area" -tells git to include the file in the next revision](https://reader030.vdocuments.us/reader030/viewer/2022040204/5ec60176f5348049da032703/html5/thumbnails/58.jpg)
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 -adds a file to "staging area" -tells git to include the file in the next revision](https://reader030.vdocuments.us/reader030/viewer/2022040204/5ec60176f5348049da032703/html5/thumbnails/59.jpg)
Branching
![Page 60: 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](https://reader030.vdocuments.us/reader030/viewer/2022040204/5ec60176f5348049da032703/html5/thumbnails/60.jpg)
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 -adds a file to "staging area" -tells git to include the file in the next revision](https://reader030.vdocuments.us/reader030/viewer/2022040204/5ec60176f5348049da032703/html5/thumbnails/61.jpg)
git branch
![Page 62: 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](https://reader030.vdocuments.us/reader030/viewer/2022040204/5ec60176f5348049da032703/html5/thumbnails/62.jpg)
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 -adds a file to "staging area" -tells git to include the file in the next revision](https://reader030.vdocuments.us/reader030/viewer/2022040204/5ec60176f5348049da032703/html5/thumbnails/63.jpg)
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 -adds a file to "staging area" -tells git to include the file in the next revision](https://reader030.vdocuments.us/reader030/viewer/2022040204/5ec60176f5348049da032703/html5/thumbnails/64.jpg)
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 -adds a file to "staging area" -tells git to include the file in the next revision](https://reader030.vdocuments.us/reader030/viewer/2022040204/5ec60176f5348049da032703/html5/thumbnails/65.jpg)
git merge
![Page 66: 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](https://reader030.vdocuments.us/reader030/viewer/2022040204/5ec60176f5348049da032703/html5/thumbnails/66.jpg)
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 -adds a file to "staging area" -tells git to include the file in the next revision](https://reader030.vdocuments.us/reader030/viewer/2022040204/5ec60176f5348049da032703/html5/thumbnails/67.jpg)
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 -adds a file to "staging area" -tells git to include the file in the next revision](https://reader030.vdocuments.us/reader030/viewer/2022040204/5ec60176f5348049da032703/html5/thumbnails/68.jpg)
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 -adds a file to "staging area" -tells git to include the file in the next revision](https://reader030.vdocuments.us/reader030/viewer/2022040204/5ec60176f5348049da032703/html5/thumbnails/69.jpg)
Pull Requests
![Page 70: 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](https://reader030.vdocuments.us/reader030/viewer/2022040204/5ec60176f5348049da032703/html5/thumbnails/70.jpg)
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 -adds a file to "staging area" -tells git to include the file in the next revision](https://reader030.vdocuments.us/reader030/viewer/2022040204/5ec60176f5348049da032703/html5/thumbnails/71.jpg)
Git and GitHubCS50 Seminar
Brian Yu