Learning goals: By the end of this notebook, you will...
Note: this is largely taken from a git workshop at CodeNeuro.
Go to GitHub and create a username and password that is easy for you to type. For the rest of this exercise, you will need to be logged in to GitHub.
On Windows, you will need to install git via git-extensions
.
There is a fantastic intiative led by Greg Wilson called Software Carpentry (SWC) to teach basic Unix/Git/Shell/Python/R/SQL skills to scientists.
For this class, we will follow the git introduction here: http://swcarpentry.github.io/git-novice/. (Feel free to check out the other lessons later).
When you get to 9. Conflict, the remote repository to use will be https://github.com/biom262/cheatsheets/
For this example, we will be using this cheatsheets repository ("repo" for short) to learn git
. Click on that link and click "Fork" (upper right). This will create your very own copy of these files.
Now, in your terminal, navigate to your home folder and create a directory where you will keep ALL your github repositories (usually a folder in your home directory like ~/code
or ~/software
or ~/workspace-git
or ~/git-repos
). hint: mkdir
.
Clone (make a local copy onto your computer) of your cheatsheets repo from GitHub (the "remote copy") with:
git clone https://github.com/username/cheatsheets.git
Now move into that directory (hint: cd
) and make sure what you see (hint: ls
) in the terminal is the same as what you see on the GitHub website.
git status
in the terminal to see what's up. Type git diff
to get a detailed list of differences. Use j
and k
to navigate up and down the diff, and q
to end the diff.git commit -am "message for the commit"
to create a new commitgit
is teaching you life lessons like overcoming fear of commitment :)git status
to see what's up.git push
to push your changes up to the github server.Imagine you're working on some code and you want to extend what you've worked on, but you REALLY SUPER want to make sure you didn't break what you already have. After all, you worked really hard on it! Thankfully, git
has exactly what we need: "branching", which is accomplished by creating "branches."
A "branch" is a concept in git where you want to work on some part of the repository, but you don't want to break what's already there. A branch lets you have your cupcakes and eat them, too, because git
stores all of the branches at once and you can switch between them!
git branch
to list out the current local branchesgit checkout -b newbranch
to create a new branchsmallchange
, I would push via git push origin smallchange
README.md
file. Now make another branch and edit the README.md
file on the same line. Try to push both branches. You should get a merge conflict. This is good. See, git is teaching you yet another life lesson: dealing with conflict!You'll use your branch from the previous section to add onto the cheatsheets
page. If you don't like that change, feel free to make a different one on a new branch.
cheatsheets
repo website (http://github.com/username/cheatsheets
),
and pressing the green "compare" button next to the branches, which looks
like this: biom262/cheatsheets
page, click where it says "(##) Contributors" (where ## is some number). Then click "Network" which will show you the literal graph network of everyone that has ever forked this repo and pushed any changes to github. Pretty cool!Awesome job! If you want to learn more about git
and Github, check out the links below.