This lab is a very brief introduction to the Git revision control system. Git is the most powerful and widely-used version control system in the world; it is primarily used by software developers but is enormously useful for any text-based document repository and is increasingly being used by humanists to share their work. You can find git repositories for most of my teaching materials, for instance.
I strongly recommend you follow this lesson up by reading the Git book, especially the first 2 or 3 chapters.
Most people love git once they start to use it, but it can be very frustrating and difficult at the beginning. We’ll go over it once, kind of quickly, then try a real-world example (checking out the next STA).
- Sign Up for a Github Account (or sign in if you already have an account)
- Navigate to my fork of the pasta-please repository
- Take a quick look at the README. Can you understand it? Maybe we need to add some extra instructions (like, what does
npm install -gmean? And where do those emoji come from?) What does the program do, and (if you can get this far) how does it work?
- Have you found where the Recipes live?
- Add a new recipe from inside Github itself(!) simply by navigating to the right spot and clicking the
+button. (see the picture below)
- Be sure to name the file “some-recipe-name.md” so that everyone knows it’s written in Markdown
- follow markdown syntax in writing your recipe
- When you save the file, Github will automatically create a forked repository under your account! Magic.
- File a pull request with me by navigating back to the main page of your repository (
github.com/your-user-name/pasta-please/) and hitting the Github pull request button:
Wow, that was cool, right? And if we get through this fast enough, we can try working from the command line.
- Choose an appropriate home for your repo and execute
git clone https://github.com/your-user-name/pasta-please.git
- Add your directory to atom as a “project directory:
- Install the “git-plus” package in Atom
- Create a new file in the appropriate place.
- Choose menu item
Packages \rarr Git Plus \rarr Add, then
Packages \rarr Git Plus \rarr Commit, then
Packages \rarr Git Plus \rarr Push
There’s still tons to learn but this is a good start.
- Sign Up for a Github Account
- Install Git on your Laptop (or use clound9, below)
- Fork the Maps Assignment
- configure your git information
- Be sure you can authenticate with github
- Create a local copy of your new Maps repository by cloning it:
git clone https://github.com/YOUR-USERNAME/maps-with-markdown
- Alternatively, set up an account with cloud9, then make sure you are logged into your github Account and connect Cloud9 to github, then follow the instructions to set up a new workspace
- Make some changes
- Commit your changes with
git commit -m "Useful Message Here" -a
- optional Push your changes to the web with
- optional Submit a pull request
Once you’ve installed Git, let’s execute our first command-line commands. In Mac, open Terminal. In Windows, open Powershell (it comes with Github Desktop). Then type
git config --global user.name "Your Name"
git config --global user.email youraddress [at] mail [dot] utoronto [dot] ca
This tells git some basic information about you, which it will use later on.
A git repository has three important “areas”, each of which represents a different “state”:
- Working Directory (Uncommitted)
- Staging Area (Staged)
- .git repository (Committed)
When you look at the repository, all you see is the working directory. So, if I want to start a new project, I create an empty directory, say, “Project”. Then I run the command:
This command creates the invisible
.git subdirectory, which is the real heart of the repo: it stores all the information about previous and current states of the repository.
Doing and Undoing
- the most elementary operation in git is “committing”; this saves your working directory to the repository. Here are the steps
- make some changes
- commit them with
git commit -a -m Message
- To inspect some other state of the repository, you will need to “checkout” that state:
git checkout HEAD~3will checkout the version you were working on 3 saves ago, for instance.
git branch # show branches git branch -c experiment # create the experiment branch git checkout experiment # chekout the experiment branch; then work on it for a while git commit -a -m "added a cool new feature, but it doesn't quite work" # commit your changes git checkout master # go back to the master branch, since it still lworks and you need to use it for something.
Push and Pull
git pull # get the most recent branch of your original repository git push # send all your commits on the current branch to the original repository
OK, that’s what I’ve got for now. Follow the excellent links near the top for more info. Good luck!