new site();

OMSCS tip: how to keep yourself from accidentally pushing to a public Git repo

2017-03-10

I'm still relatively new to the OMSCS, but even I've noticed that a common problem for people is not knowing how to use Git effectively in the context of the program. Some people have never had to use Git at all, which is fine; there are many VCS options out there and Git happens to be one. Other people have used it but not for the particular purpose we use it for in the program. Since some of the features, workflow, and terminology can be odd or unfamiliar even to people who have used other source control systems, I figured I could write this up and maybe help somebody.

If that doesn't fix it, git.txt contains the phone number of a friend of mine who understands git. Just wait through a few minutes of 'It's really pretty simple, just think of branches as...' and eventually you'll learn the commands that will fix everything.

Class repos are (usually) pull-only

The situation is usually, basically, this: there is some canonical (class) repository, from which you are expected to pull, and then you are on your own for where you store your changes, if at all. You can't push your work back to the class repo, since everyone else would see it. We discovered this semester that a push to a repo to which you do not have permission will become a pull request, which will be visible to everyone and will therefore be an honor code violation. So, do not try to push to the class repo.

Forks of the class repo will not be private, since the class repo is public

You can't store your class work publicly, even after the class is over, since future students shouldn't be able to grab your work and copy it. Creating a fork is (in other contexts) a fine idea, but the steps required are kind of involved and there is an easier way:

You can set it up so that your stuff gets pushed to your own personal repo but you can still pull from the class repo

Periodically during the semester you will need to get updates from the class repo, so you have to maintain your connection to it. But you also really should be pushing your work somewhere, especially if you wind up getting accused of plagiarism--it's wise to have a paper trail, just in case. What you want is to be able to keep your connection to the class repo, but make it pull-only, and at the same time have a second connection to your private repo, where you can both push and pull to support a typical workflow.

To do this, you just need to add a remote for your private repo with push/pull enabled, and then redirect any accidental push requests to the class repo to some dead-end. Here's an example from ML4T:

tlawson@tl:~/cs7646$ git clone https://github.gatech.edu/ta_account/ML4T_2017Spring.git

tlawson@tl:~/cs7646$ git remote -v
origin https://github.gatech.edu/ta_account/ML4T_2017Spring.git (fetch)
origin https://github.gatech.edu/ta_account/ML4T_2017Spring.git (push)

tlawson@tl:~/cs7646$ git remote add personal https://github.com/YourName/cs7646

tlawson@tl:~/cs7646$ git remote set-url --push origin DO_NOT_PUSH_TO_THIS_REPO

tlawson@tl:~/cs7646$ git remote -v 
origin https://github.gatech.edu/ta_account/ML4T_2017Spring.git (fetch)
origin  DO_NOT_PUSH_TO_THIS_REPO (push)
personal https://github.com/YourName/cs7646 (fetch)
personal https://github.com/YourName/cs7646 (push)

So if you try to push to the origin remote, it will look like this:

tlawson@tl:~/cs7646$ git push origin master
fatal: 'DO_NOT_PUSH_TO_THIS_REPO' does not appear to be a git repository
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

Having a name like DO_NOT_PUSH_TO_THIS_REPO will hopefully remind you to instead do it like this:

tlawson@tl:~/cs7646$ git push personal master

Hopefully this is helpful; if anything isn't clear or needs updating, feel free to let me know.

Tags: