Git Usage Guide for Assignments - douglascraigschmidt/CS253 GitHub Wiki

This guide is intended to help you correctly apply Git commands to your GitLab repository using Git Bash. There are two parts: (1) Set up a git folder on your local machine and (2) how to pull new assignments (e.g., assignment1a to assignment1b).

  1. Setting up git folder on your local machine

a. At this point, assuming assignment1a has been pulled to your machine, you should have a folder that looks similar to this: RootFolder

The following command was used to see all files and folders (including hidden ones):

ls -al

As we can see there are two folders, a README.md file and one hidden file .git (it could be a hidden .git folder instead on yours).

b. Next, we need to check our remotes, these are the remote repositories we have pointed to from this local repo: RemoteRepos

The following command was used to look at all git remote in a more verbose (more detailed) manner:

git remote -v

As we can see there are two remotes, "origin" and "skeleton", both have fetch and push capabilities. "origin" is connected to the remote repository at GitLab, while skeleton is connected to the remote repository at GitHub. Don't worry about the different url format, this is if you're using ssh or https as protocol method (Read more on the differences here

c. Finally, we need to configure our upstream remote. This is so when you do "git push" without any options attached, it will automatically push to origin/master. GitPush

The following command was used to inspect which upstream do we have currently:

git branch -vv

As we can see, my local master branch (we only have one branch) has our upstream point to remote repo origin at branch master with commit hash number 6a8d401 with message "fix to Doug's specs" (it even tells us right now my local is 2 git commits behind).

We want our upstream to point to origin/master so as to make sure to push and pull to the correct repo (since we can't push to Doug's/GitHub/skeleton).

If yours isn't similar to this, you can set your upstream to origin/master (while in local master branch) with:

git branch --set-upstream-to origin/master

You will see something similar to this if you do: SetUpstream

  1. How to pull new assignments (example: 1a to 1b)

Ok, so assuming right now, the latest commit in the repo is the one that finished assignment1a, and that your origin/master (GitLab remote) is also at the same commit, and now assignment1b has just been released. We have changed only two files in assignment1a. To get the new assignment from GitHub, we need to run:

git pull skeleton master

This command bypasses the upstream by attaching the option of "skeleton master", which means we want to get commits from branch "master" of remote "skeleton". Note I did not attach the option "-f" or "--force" (as this would overwrite).

Now there are two possibilities that could happen when we pull like this, let's walk it through:

A. There is a merge conflict:

Let's say the instructor wants us to further modify those two files again, but because everyone has different implementations of the code, he wants to start us all off with the same baseline level of code. This means some people will have code in conflict with the skeletons. If this happens, well, uhhhh, you would have to solve some merge conflicts. Try this guide from GitHub.

B. There is an automatic merge:

git is smart at merging and it will try to automatically make changes to code that doesn't interfere with existing ones. In fact, for going from assignment1a to assignment1b, option B will happen. It's also likely that option B will be the case for the rest of the semester. Why? it's unlikely that we will revisit old problems with conflicting standardized code in subsequent homeworks.

What might throw you for a loop in option B is a screen that looks like this might pop up: PopUp

This might be very scary at first, and your keyboard is seemingly non-responsive. Don't worry, this is the vi/vim text editor that comes with bash, this is what's hidden from you when you do ' git commit -m "message" ' . The screen is showing the commit message because automatic merging counts as an important action and also automatically need a commit. Search up how to "quit vim" and you can exit out with that automatic message, or maybe mess around and edit your message in vim. If you get fast in vim your productivity will increase, or you can also change to a different text editor, such as emacs.

With that, we are done with setting up our folder and know how to pull assignments.