We will be using Git, GitHub, and GitHub Classroom in this class to manage assignments, labs, and projects. Git is version management software used to keep a set of files related to a single assignment, lab, or project in a single unit called a Git repository. We will use GitHub Classroom to enable you to create your own private or team repository for each assignment, lab, or project. Each repository will be initialized with the files the Professor provides, including a "README.md" file that contains the instructions for the assignment, lab, or project. The Professor and TA's have access to your repository, and can provide advice, and grade your results once the assignment due date occurs.
We will be using Github to submit your labs and assignments throughout this course. You will need a Github account, so if you don't have one already, go to https://github.com and sign up to get a free GitHub password and userid.
The professor and TA's need to know your GitHub userid so that we know whose work we are grading. Once you have signed up for an account, go to myCourses, click on "Homework Submissions", and fill out the GitHub Userid survey, which simply asks you for your GitHub userid.
When the CA's and TA's grade the first assignment, they will check the results of your GitHub Userid survey to figure out your GitHub userid and grade the assignments and labs. After verifying that your GitHub userid is correct, the CA's or TA's will copy your GitHub Userid into the Grade Center "GitHub Userid" column. If there are any problems, please contact the TA responsible for your lab section.
arrow_backWhen you use GitHub, you need to provide your GitHub userid and password. Many web browsers such as the Google Chrome web browser remember your GitHub userid and password for you. (If you have multiple GitHub accounts, this can become confusing, so it's easiest to use just one account.) Integrated Development Environments such as Eclipse can also often save your GitHub userid and password for you. However, when we are using git in a command line mode, git will often prompt for your userid and password every time you do most git commands.
One alternative is to install a Git "Credential Manager" that can save your git userid and password and provide it to Git whenever it needs it. The one I use is Git-Credential-Manager Core, which has a free MIT license, and can be installed on Windows, Mac, or Linux. Once I installed this on my Windows machine, and provided my userid and password on the command line once, GCM-core remembered my Git userid and password from then on!
arrow_backIn CS-140, we will be using two basic workflows, depending on whether an assignment is an individual assignment, or, as in the case of labs and projects, the assignment is a team assignment.
The Professor will create a GitHub Classroom assignment for each homework assignment or lab, and provide the invitation URL for that assignment to you. If you want to try things out, here is a test invitation link(It's probably easiest to right click, and select "Open link in a new tab" so you can flip back to these instructions.)
When you navigate to the invitation link for the first time, GitHub Classroom will ask you if you wish to accept the invitation, such as in the following illustration:
When you press the "Accept this assignment" button, then GitHub Classroom will automatically create a private repository for you, initialized with any template code or instructions the Professor has provided. (You may need to log in to Git with your Git Userid and Password before the accept is complete, but once you've logged in once on the current system, you should get a cookie for Git that remembers your userid and password.) You well get a "ready to go" screen, like:
The repository name will start with whatever prefix the Professor has specified (usually "lab01" or "hw01" and so on), followed by a dash, followed by your Git userid. For instance, if you accept the test invitation above, you will get a repository called "test-userid", where userid is your Git userid.
You will see that the "ready to go" screen contains a hyperlink to the web browser view of your master repository. This is the URL associated with your master repository, and it consists of the prefix, https://, followed by the address of the Microsoft GitHub site, github.com, followed by our class organization name, which in this case is BinghamtonUniversityCS140, followed by the repository name itself. You can click on this hyperlink to view your new repository.
If you navigate to the invitation link after you have accepted the invitation, GitHub Classroom will take you straight to the "ready to go" screen without making you re-accept.
arrow_back
When you open a view of your repository in the web, you are looking at the cloud version of your repository. The upper left of the screen has links to the organization (class) you belong to, the repository, and the repository used to initialize your private repository. Under that are several tabs, with the leftmost tab called "Code" highlighted. This is the tab we will use almost exclusively (although we may use the "Issues" tab for automated assistance from the CA's or professor.)
Underneath the orange horizontal line, on the right of the screen, is a green "Clone or download" button. If you click on that button, You will see the URL associated with this repository. Click on the clipboard icon to copy that URL to your cut/paste buffer. This is the URL that you will need to clone your repository.
If you keep reading down, you will see the list of files in the repository, including any java code provided by the instructor or added by you, once you commit new code files. These are hyperlinks so you can look at the code in those files.
The last thing in the "Code" tab is "README.md". The .md file type is markdown, which enables the Professor to provide a formatted set of instructions that describe how to complete the assignment.
In the "Code" tab is a link to "commits". If you click on that link, you will see the history of this repository, showing each committed version of that repository. You can use this link to go back to earlier versions.
If you click on the clipboard icon, you will save the commit hash code for the specific commit in your cut-paste buffer. Clicking on the hashcode itself shows the changes made at that commit level from the previous level. Click on the <> button to see the code in the repository at that commit level.
arrow_backWhen you look at your repository using a web browser, you are looking at the master copy of your repository. You will need a local copy of the repository on disk in order to edit, compile, and test any changes to the repository. You make a local copy of your repository by cloning it.
Clone your repository by opening a command line window on the machine where you want to create a cloned copy of the repsository. Then run the command git clone url, where url is the URL that describes your repository. You can get this URL by looking at your repository in the web browser, and clicking on the green "Clone or Download" button.
When you hit enter, Git may ask for your git Userid and password. Once you enter these, git will make a sub-directory of the current directory named with the repository name. If you "cd" to this subdirectory (make it your current directory), then you will see all of the files in that directory. You may edit these files, compile them, and test them in your local repository. Remember, you are updated the local cloned version of the repository, not the master repository.
See git clone for complete documentation of the git clone command.
arrow_backGit keeps track of a specific list of files. If you create new files in a local repository directory, Git does not know about those files. You need to perform a special action to add those files to your repository. This is done by using the command git add file(s) where file(s) is the full file name of a specific file or list of files that you want Git to include as part of your repository.
Note that the git add command only updates your local repository, not the master repository. The added files need to be committed and pushed to make it to the master repository.
See git add for complete documentation of the git add command.
arrow_backYou can use the git status command from your local repository to check the current status of your repository. The git status command will tell you:
See git status for complete documentation of the git status command.
arrow_backOnce you have made and tested all the changes to your local repository (including adding files using git add if there are new files), use the git commit -a -m"commit comment" command to indicate that you are happy with your changes and you intend to move those changes to the master repository.
The commit comment is a line of text associated with these changes so you can remember what you changed.
The "-a" flag tells the commit command to commit anything that has changed. (If you don't specify the -a flag, then you need to include the names of all the changed files on the git commit command line.) You may want to run the "git status" command after running git commit to make sure everything has been committed corrrectly.
Git generates a commit hash code that can be used to indentify the specific version of your repository associated with the commit.
Remember, the git commit command does not update the master repository. You are only committing the changes in the local version of the repository. You still need a git push command to copy those committed changes to the master repository.
You can see all the committed versions of you master repository on the repository web site.
Multiple commits make sense... it's like saving a file in case the system goes down. The more often you commit, the more likely there will be a state you can go back to, before you made a mistake.
See git commit for complete documentation of the git commit command.
arrow_backOnce you have committed changes to your local repository, the next step is to copy those changes to the master repository. This can be done using the git push command. The git push command will copy any committed changes from the local copy of the repository and copy those changes to the master version of the repository. After you complete a git push, you may want to look at the master version of the repository on the web and make sure the changes you expected are reflected in the master version. You may have to hit the "refresh" button in your browser to see those changes, and GitHub warns that sometimes it takes up to 10 minutes for those changes to get reflected, although usually, changes seem to occur almost immediately.
You can also use a git status command to make sure you changes have been pushed to the master.
See git push for complete documentation of the git push command.
arrow_backMost of the time, we will only be using a single local version (clone) of a repository, but if you ever have occastion to have mutliple local versions of a repository, and you use one local version to commit and push changes to the master, then the second copy of the repository will not have those changes. In this case, when you want to work on the second version of the repository, start off with a git pull command. The git pull command tells git to pull any changes in the master repository that have not been made to the local copy into the local copy.
If you don't remember to do a git pull in the second copy of your repository, and start making changes to the second copy, those changes could conflict with the changes made to the master, and could cause problems. To avoid these problems, it's best to always do a git status at the start of a session, and do a git pull if there are any changes to the master that need to be propagated locally when you are using multiple clones of a repository.
See git pull for complete documentation of the git pull command.
arrow_backIf the local repository A changes don't interact with the local repository B changes (for instance, the A changes and B changes were on different files, or different parts of the same file), then allow git to automatically merge the changes. If the A and B changes were to the same part of the same file, then you will need to accept the A changes or the B changes, and manually remake whichever changes you did not accept.
It's best to avoid conflicts altogether. Avoid conflicts by only making changes to one local repository at a time. When those changes are complete, commit and push those changes to the master, and then be sure to pull those changes in any other local repository before changing anything else.