Git and Github - mnielsen/Notebook GitHub Wiki
#Git and GitHub#
[TOC]
##Basic git setup##
###Installing git
:###
sudo apt-get install git-core git-doc
On a machine with a gui, add git-gui
to the end of the last line.
On first install:
git config --global user.name “Michael Nielsen”
git config --global user.email “[email protected]”
git config --global core.editor emacs
git config --global alias.co checkout
In general, we can retrieve the values by:
git config user.email # returns: [email protected]
git config --list # returns: all variables
We can set up more aliases by:
git config --global alias.name command
###Creating a new local git repository###
git init
touch README
git add .
git commit –am “First commit.”
##Basic github setup##
###Setting up ssh keys and accesses at github###
These keys and accesses only need to be set up the first time. On subsequent occasions you can skip to the next section.
The most useful resource for this is Github's useful help page.
cd ~/.ssh # May need to make the directory first
ssh-keygen -t rsa -C "[email protected]"
Then add the public key to GitHub, via “Account Settings” > “SSH
Public Keys” > “Add another public key”. Cut-and-paste the contents
of id_rsa.pub
into the "Key" field.
Test that the keys have worked with:
ssh -T [email protected]
This should authenticate, although you can't log in.
Configure so git knows about github account:
git config --global github.username mnielsen
git config --global github.token TOKEN # TOKEN may be found under “Account Settings” > “Account Admin”
###Setting up my new git repository on github###
This will typically happen immediately after I've created a local git repository, as described above.
If I'm running on Windows (not so often any more), start pageant
,
and add required key
git remote add origin [email protected]:mnielsen/repo.git
git push origin master
##GitIgnore##
Add lines like the following to .gitignore
:
*file*
dir/*
See the diffs on today's work under git:
git diff --stat @{yesterday}..HEAD
Omit --stat
to get the full diff.
Remotes
List all remotes:
git remote
Add a remote:
git remote add remote_name [email protected]:mnielsen/repo_name.git