Download presentation
Presentation is loading. Please wait.
1
Version Control with GitHub
Computer Science 209 Version Control with GitHub Computer Science 209 1
2
What is GitHub? A code hosting platform for version control and collaboration Facilitates collaboration Uses repositories, branches, commits, and Pull Requests Available as command-line or GUI What is GitHub? A code hosting platform for version control and collaboration Facilitates collaboration Uses repositories, branches, commits, and Pull Requests Available as command-line or GUI 2
3
Downloading GitHub Desktop
The GUI provided by GitHub You must also make a GitHub account Downloading GitHub Desktop The GUI provided by GitHub You must also make a GitHub account 3
4
Repositories A repository is usually used to organize a single project
Repositories can contain anything your project needs Files, folders, images, etc GitHub uses repositories as a controllable folder for your project Repositories A repository is usually used to organize a single project Repositories can contain anything your project needs Files, folders, images, etc GitHub uses repositories as a controllable folder for your project 4
5
Creating a Repository in GitHub Desktop
Select New repository Either on the right side of the screen or under the File menu Name your repository Write a short description Select public or private accessibility (Optionally) Select Initialize this repository with a README Click Create Repository Creating a Repository in GitHub Desktop Select New repository Either on the right side of the screen or under the File menu Name your repository Write a short description Select public or private accessibility (Optionally) Select Initialize this repository with a README Click Create Repository 5
6
File Location GitHub will manage the files on your local computer for you You can access these files with Ctrl+Shift+F on windows Edits made locally to these files will be detected by GitHub Desktop These files will also update to your current branch of code File Location GitHub will manage the files on your local computer for you You can access these files with Ctrl+Shift+F on windows Edits made locally to these files will be detected by GitHub Desktop These files will also update to your current branch of code 6
7
Master Branch By default the repo has one branch named master
The master branch is the "definitive branch" Other branches are created for making edits to the master Once satisfied with the edits, the branch is then committed to the master In general, don't edit the master branch Master Branch By default the repo has one branch named master The master branch is the "definitive branch" Other branches are created for making edits to the master Once satisfied with the edits, the branch is then committed to the master In general, don't edit the master branch 7
8
Branches Have you ever saved different versions of a file?
story.txt story-liz-edit.txt story-liz-edit-final.txt Branches accomplish similar goals in GitHub repositories Creating a branch off the master branch is making a copy of master As it was at that point in time Branches Have you ever saved different versions of a file? story.txt story-liz-edit.txt story-liz-edit-final.txt Branches accomplish similar goals in GitHub repositories Creating a branch off the master branch is making a copy of master As it was at that point in time 8
9
Making a Branch Go to your repository
Click the drop down at the top of the file list that says branch: master Type a branch name into the new branch text box Select the blue Create branch box or hit Enter on your keyboard The branch will be identical to the master until edits are made Making a Branch Go to your repository Click the drop down at the top of the file list that says branch: master Type a branch name into the new branch text box Select the blue Create branch box or hit Enter on your keyboard The branch will be identical to the master until edits are made 9
10
Switching Branches Selecting the drop-down menu at the top will let you switch between published branches GitHub will automatically change the files on your local computer Give it a little time to update on larger projects Make sure you're on the correct branch before editing any files! Switching Branches Selecting the drop-down menu at the top will let you switch between published branches GitHub will automatically change the files on your local computer Give it a little time to update on larger projects Make sure you're on the correct branch before editing any files! 10
11
Making Edits and Running Programs
You can use any editor of your choice on the files in the GitHub repo It behaves just like any other folder on your computer Same for running the code javac, java Saving locally will not save to the repo branch To save to the branch you must commit the edits Making Edits and Running Programs You can use any editor of your choice on the files in the GitHub repo It behaves just like any other folder on your computer Same for running the code javac, java Saving locally will not save to the repo branch To save to the branch you must commit the edits 11
12
Committing On GitHub, saved changes are called commits
Each commit has an associated commit message A description explaining why a particular change was made Commit messages capture the history of your changes Other contributors can understand what you’ve done and why Committing also shows how frequently you are working on your code This will be important for projects 5 onwards Committing On GitHub, saved changes are called commits Each commit has an associated commit message A description explaining why a particular change was made Commit messages capture the history of your changes Other contributors can understand what you’ve done and why Committing also shows how frequently you are working on your code This will be important for projects 3-5 12
13
Edit and Commit Open the file you wish to edit Make edits
Write a commit message Describe your changes briefly in the summary bar More details can go in the box in the larger text box Click the blue commit button to save to the current branch You can select which files are committed with the checkboxes to the left of the files Open the file you wish to edit Make edits Write a commit message Describe your changes briefly in the summary bar More details can go in the box in the larger text box Click the blue commit button to save to the current branch You can select which files are committed with the checkboxes to the left of the files
14
Differences GitHub Desktop will show you a visualization of the changes made Red means removed Green means added Differences GitHub Desktop will show you a visualization of the changes made Red means removed Green means added 14
15
Pushing Committing will only update your local repo
Making a push request will update the repo online So that other collaborators can see the changes In order to finally accept the new edits as final, a pull request is needed Push by using the blue button or typing Ctrl+P Pushing Committing will only update your local repo Making a push request will update the repo online So that other collaborators can see the changes In order to finally accept the new edits as final, a pull request is needed Push by using the blue button or typing Ctrl+P 15
16
Pull Requests Pull request propose your changes to the rest of your collaborators Requesting that someone review the code Finally pull in your contribution and merge them into their branch Pull requests show diffs (differences) of the content from both branches The changes, additions, and subtractions are shown in green and red Pull Requests Pull request propose your changes to the rest of your collaborators Requesting that someone review the code Finally pull in your contribution and merge them into their branch Pull requests show diffs (differences) of the content from both branches The changes, additions, and subtractions are shown in green and red 16
17
More on Pulling in your pull request message will tag that user in the request You can even open pull requests in your own repository and merge them yourself A great way to learn the GitHub flow before working on larger projects More on Pulling in your pull request message will tag that user in the request You can even open pull requests in your own repository and merge them yourself A great way to learn the GitHub flow before working on larger projects 17
18
How to Make a Pull Request
Click the blue "pull request" button You must be logged in to GitHub for this page to load If you get a 404 error, log in! Fill out information about your edits Click create pull request How to Make a Pull Request Click the blue "pull request" button You must be logged in to GitHub for this page to load If you get a 404 error, log in! Fill out information about your edits Click create pull request 18
19
Finally, Merging When a branch is complete it’s time to bring the changes together A branch can be considered complete when one new element is added which does not break the code Everything still compiles, other tests do not crash, etc. This is achieved by merging the branch into the master branch Finally, Merging When a branch is complete it’s time to bring the changes together A branch can be considered complete when one new element is added which does not break the code Everything still compiles, other tests do not crash, etc. This is achieved by merging the branch into the master branch 19
20
How to Merge a Branch Click the green Merge pull request button to merge the changes into master Click Confirm merge Delete the branch with the Delete branch button in the purple box Since its changes have been incorporated it is no longer needed How to Merge a Branch Click the green Merge pull request button to merge the changes into master Click Confirm merge Delete the branch with the Delete branch button in the purple box Since its changes have been incorporated it is no longer needed 20
21
Conflicts The bane of every GitHub user's existence is conflicts between local check-outs of repos If two people change the same file in different ways, GitHub does not know which one to use Avoid conflicts at all costs! Never work on the same file as another user Communicate with your team All else fails… nuke it Save your edits somewhere else and check out a new copy of the master branch Conflicts The bane of every GitHub's existence is conflicts between local check-outs of repos If two people change the same file in different ways, GitHub does not know which one to use Avoid conflicts at all costs! Never work on the same file as another user Communicate with your team All else fails… nuke it Save your edits somewhere else and check out a new copy of the master branch 21
Similar presentations
© 2025 SlidePlayer.com Inc.
All rights reserved.