CSCI 352: Software Engineering
Many thanks to Dr. Guerin for sharing this with us
Software Engineering Toolkit 4.0: Basic Version Control with git.
Due: 1/25 before the start of class
NOTE: Screencaps of individual steps will get bonus points if I use them in the next iteration of this course!! Make sure to label your screencaps and tell me where they would be useful!
Libraries You May Use
We will be hijacking one of Dr. An's CS325 assignments to practice working with git. This is meant to be a classwork activity, and will be due before the next class period (in case you don't get all the way through it by the end of the class period). Once you have completed this tutorial, I will provide you with the information needed to get to the class private repository. Note: do not place your class projects in a public repository.
In practice, a version control system (VCS) is typically the preferred route for the world of software engineering/computer science. Version control software packages are used to track and manage changes to documents, programs, web pages, and just about any other (typically text based) systems that are under active development. The git software package was also developed by Linus Torvalds (of Linux fame), and among other things (e.g., the primary purpose was for Linux kernel development) has become a relatively popular version control system in the real world of software engineering. (Other options exist, however for the purposes of this course we will be focusing on just the one package.)
Advantages of using version control include:
- You can choose when and how to save any changes to the VCS.
- At virtually any time you can view or revert back to older versions of your software (in case you wish to simply see older work or in the extreme if you mess something up).
- Along with managing local copies of your entire code history, most VCS's integrate with web (read: "cloud") services that can also safely manage a copy of your source for retrieval anywhere in the world.
- (Due to the previously described cloud integration) Your work is no longer stuck on one machine or system, but can easily be worked on in a number of locations, with all changes managed in a central fashion.
- Most modern systems are designed with collaboration in mind, so numerous individuals or teams can work on submitting changes to the same project, with changes collected centrally on the cloud server.
- These days many employers will view a public set of projects hosted online as a positive, so as you accumulate large (and cool) projects like your CSCI 495: Senior Design Project, you can post them for the world (and any prospective employers) to see.
- Most importantly, no more:
- accidentally deleting your code before a due date so you have nothing to submit for an assignment,
- worrying about using thumb drives or email attachments to collaborate with others,
- sitting down to add a new feature or debug something that is not working and making things worse by doing so!
Getting signed up with github.
- First, go to github.com and sign up for an account using your university email address. (Some of you may have done this already).
- Github is one of the many industry-standard cloud service providers for git, and so we will start out by using some of the many advantages of such a service right off the bat!
- When you load the page you should immediately be greeted with the ability to sign up either directly on the front page, or with the sign up button in the top-right.
- NOTE: Make sure your GitHub account is linked to your university email, and it is publicly searchable. Furthermore, make sure that your username is linked to your real name or university email handle - Prospective employers will see this!
After you have signed up for your github account, go to your profile (in the upper-right corner of the webpage there should be a dropdown with your github identicon. You will have the ability to upload your own image, but unless you feel like it github will generate a 5x5 "pixel sprite" automatically from your user id. Mine looks like . At any time you should always be able to navigate back to your profile in this way.
In your profile, select the tab. A repository (or repo is essentially a VCS database where all of your project information is stored remotely.
At the start this tab should read that you don't currently have any public repositories. Click the icon to create a new repo.
On the new repository page use the following information to initialize your repository:
- Name: Git Test
- Description: A sandbox for getting used to using git for version control.
- Leave selected. As a business model, github charges for multiple private repos. Plus, I don't think there will really be anything here worth worrying about if someone else happens to find it. You can always delete your repo after the semester if you really want, but you may find it worth keeping around so you can continue to practice without worrying about damaging an active project.
- The remaining fields you can leave blank.
- Click to create your online repository.
- You may want to save the resulting page for a moment (print, screencap, etc.) so you can refer back to it. If you lose track it will not be a big deal, however I often use the links and commands they provide so that I can quickly copy-paste when I create a new repo.
- Next, we will be creating a project locally and linking it to your repo.
Creating your project.
This will work a bit differently than how it did on the Linux machines in 325.
- First, you will need to have VisualStudio create a new local git repo
NOTE: it is not the end of the world if you miss this, it's just going to be a bit tricksier.
- Start a new console project in VisualStudio
- Before clicking OK to create your project:
- Make sure you are not saving to the local machine, but your network drive
- Select the option "Create new Git repository" (check the bottom right corner)
- Now you have a local repository, we will need to connect it to your remote repository (on github.com)
- Click on the Team Explorer tab, and select Publish
- Open the "Publish to Remote Repository" option, and enter in the url of your new public Git Repo
- NOTE: Windows Security will pop up a window: put in your GitHub credentials to proceed
- After VisualStudio finishes publishing, you should be able to refresh your repository window, and see your solution!
- At this point, you should have an empty console project. Modify it to a simple "Hello World!" application.
- After ensuring that your code runs correctly, make sure to push it to your remote repository.
- To push your code, go to the TeamExplorer window, and select Changes. You should be able to see that your program.cs (assuming you kept the default name) file was changed.
- Sometime around here, Windows will prompt you for your name and email address for making commits to GitHub - it is most useful if you fill these in, as opposed to leaving them at the defaults
- Write a brief message in the commit messages window
- Push the Commit All button to commit it to the local repository
- Switch to the Synchronize view in the TeamExplorer window, and push your work to your remote repository.
- Use the online repository browser to ensure that your Hello World has successfully been synched.
Tracking your progress: Diffs and commits.
- Modify your program to become a simple number guessing guessing game
Build and run your code to ensure that it actually works
DON'T COMMIT OR PUSH CHANGES YET!!!
Go to the TeamExplorer window and select Changes, you should see that Program.cs was modified. Double-click on it!
This opens up VisualStudio's Diff. You should see your current code on the right, with what is stored in the remote repo on the left
Create a commit message and commit your code to the local repository.
Switch to the Synchronize view, and push to the remote repository
- Inform the user that you are thinking of a number between 0 and 100
- Use a random number generator to generate this number
- Allow user to guess numbers - report back if the guess is too low, too high, or the correct value
- On a correct guess, inform the user how many tries it took, and then exit
Creating and merging branches.
- Have you ever found yourself creating multiple files (main.cpp, main.old.cpp) to save your old work in case you introduce new (and problematic) errors while you are trying to add a new feature or fix a bug? (I've found myself having to resort to this in a pinch.)
- By default your project has a single "branch" called master (as in origin master. You can create an arbitrary number of "branches" from any point in your commit chain in order to add a new feature.
- Create a new branch by clicking the icon, and type feature in the box. Normally you would create a more descriptive name for the feature you were working on. At this point you can use the drop-down to view both branches, however the files and their contents should be identical.
- In VisualStudio, switch to the Branches view of the TeamExplorer window. Look for your new branch under the remote repositories section.
- Add a new feature to your Program.cs: allow the user to selecting a starting number (x) and a stopping number (y). Your program should now start by prompting the user for these 2 numbers, then using them as bounds for your number-guessing game (I am thinking of a number from x to y...)
- Commit and push. Check that your modifications made it into your new branch (and only your new branch) through the online repository browser.
- Now that we have implemented the feature to our liking we merge the changes back into our master branch. We are going to do this through VisualStudio.
- Go back to the Branches view in TeamExplorer, and right-click on your local copy of master. Select Checkout... Double-check that this has reverted you back to your original Program.cs
- In the Branches view in TeamExplorer, select Merge at the upper right. You will tell it to merge from Feature into master.
- After doing this, make sure to commit all changes, and push them to your remote repository.
- Congratulations! You are now ready to start using version control like a professional! We will be starting with a version controlled (through git) version of your next programming assignment.
Adding a collaborator.
- For this assignment you will not submit using email, you will simply add me to the project.
- On your project page click then . In the search box, you can find me by email (firstname.lastname@example.org). Click to "Add collaborator", and you are done.
- In a real-world project you may have a number of collaborators, including your partner for this course.
What you must turn in.
Nothing. Once you have added me as a collaborator I will be able to view your project, your commit history, and anything else that I need.
Note: Your program must compile and run on a G1 lab machine or it will not be graded. Please see the syllabus for details.