-
Notifications
You must be signed in to change notification settings - Fork 13
Quick tutorial on GitHub
Here, we'll assume you're working on one of MSKCC's clusters - luna, saba2, hal, unagi, miso-dev, or dashi-dev. All these nodes have git installed, but not always the same version.
Let's start with setting up a decent ~/.gitconfig
, at least to tell git who you are. Modify name and email below to your own, preferably using the email that you registered with, at: https://github.com/settings/emails
git config --global user.name "Cookie Monster"
git config --global user.email monsterc@mskcc.org
To enable color highlighting in git's command-line interface, run the following:
git config --global color.status auto
git config --global color.diff auto
git config --global color.branch auto
git config --global color.interactive auto
You can also tell git to use a different text editor when you type commit messages:
git config --global core.editor vim
Find a nice folder where you can clone a local version of the repository, ~/src
for example. Then here is how you would clone the CMO documentation repository into ~/src/cmo-docs
:
git clone https://github.com/mskcc/cmo.git ~/src/cmo-docs
When cloning a private repo, the command above asks for your GitHub username and password. It does this every time you interact with the remote repository. You can run the following to make git remember your credentials for 2 hours:
git config --global credential.helper cache
git config --global credential.helper 'cache --timeout=7200'
Let's get into the repo, and edit a file. Use your own github ID below, in place of cmonster
:
cd ~/src/cmo-docs
echo cmonster >> github_ids.txt
Now use git status
to see all the files/folders that have been added/modified/removed:
git status
You will definitely see github_ids.txt
as modified. Now let's see how it differs from the repo's committed version:
git diff github_ids.txt
Let's add
this to the list of changes we want to commit
. When writing code, you'd only do this step after you've checked over your code for bugs and it seems to work fine:
git add github_ids.txt
Let's use git status
again to see all the changes that we are ready to commit
:
git status
Now we can commit
to those changes with a short message summarizing them:
git commit -m "Added my UID to github_ids.txt"
The commit you made is only reflected in your local copy of the repository. This especially helps in large collaborative projects where your small change might break everyone else's work. When you're confident and ready to share all your commits, then push
to Github:
git push
That's it! You may be asked to enter your Github credentials, but you don't have to define any URL or path, because all the necessary configuration is in the .git
subfolder. Take a peek:
cat .git/config
That's a basic tutorial to get you started. Look for much more at https://git-scm.com/documentation