Github

Nathaniel V. KELSO edited this page May 9, 2013 · 29 revisions

Git aka Github

Prefer pretty pictures slides? Check out Roger Dudler's Git Guide

Alternative guide: Install git, add it to the path

Another GIT reference »

When to commit, init commit and readmes

To check a project out:

git clone git@github.com:Citytracking/toner.git toner

To check a branch of a project out:

git clone git@github.com:Citytracking/toner.git toner

To switch to a new branch (will also make it if it's not existing):

git checkout -b tilefarm-redeploy

To check out a locally managed git repo (that isn't on github.com):

git clone ssh://user@sub.domain.com/var/git/serverprojectname localprojectname

** WARNING: if you have changes that aren't yet committed, and you want to save them for use later:**

git stash save

then to get them back later:

git stash pop

then make sure you’re in the right branch

(if a project has been forked somehow):

git checkout -b highroad-rework remotes/origin/highroad-rework

If I want to switch to another branch (like the 'master'):

git checkout master

then to confirm:

git branch -v

should print out:

* highroad-rework 76e0e3d comment1111

master 490a0a5 Fixed broken merge in Makefile

with the * being the active branch

To list different origins (forks) of the same project

git remote -v

To add another origin:

git remote add upstream git@github.com:migurski/Dymo.git

where “upstream” is the name of the origin that I specify, the git@* is the thing copied from github’s project page

To get the changes from the other fork/branch:

git pull upstream master

To see what Git thinks changed:

git status

To commit everything:

git commit -m "meaningful message" -a

To commit just specific file (multiple okay):

git commit -m "meaningful message" file1 file2 file3

Then to really push it up to github.com (I’m in the highroad-rework branch):

git push origin highroad-rework

To get more specific with your last commit message, after the fact:

git commit --amend

To update your files compared to the server files:

git status

to make sure you’ve checked in

then

git pull origin forkname

Make a mistake (oops!) and need to revert files back to the latest commit?

Make sure you're in the right branch first!

git checkout *

Or a specific file:

git checkout path/filename.ext

Github is odd about rsa security keys:

Use the same one as on your main drive:

scp .ssh/id_rsa* brillo.stamen:.ssh/

More about SSH / RSA keys »

_which means: secure copy SPLAT to OTHERPLACE _

github-cant-push-to-master

http://stackoverflow.com/questions/7548661/git-github-cant-push-to-master

fatal: remote error: You can't push to git://github.com/my_user_name/my_repo.git Use git@github.com:my_user_name/my_repo.git

Instead:

git remote set-url origin git@github.com:my_user_name/my_repo.git

Tagging versions

http://learn.github.com/p/tagging.html

Bridging from SVN to Git

Loose connection:

cd docroot/projectname/svn-git/
git svn fetch
git svn rebase 
git update-server-info

For those who prefer git over svn, there seems to be an easy solution.

  1. mkdir {projectname} # this is the directory where you will keep your git checkout
  2. cd {projectname}
  3. git init # initialize a fresh new git repository there
  4. git svn init --stdlayout svn+ssh://[yourusername]@sub.domain.com/var/svn/projectname # connect it to SVN server
  5. git svn fetch # fetch data from SVN and...
  6. git svn rebase # apply it to the local repository

Commit as usual during the project:

  1. git commit -m '[message]' -a

When you've made a local change, it's one step:

  1. git stash save && git svn dcommit && git stash pop # push your local changes to SVN

To get someone else's changes:

  1. git stash save && git svn fetch && git svn rebase && git stash pop

Now the everything should be back in sync.

Make sure you have a consistent Github personality across all machines:

git config --global user.name "First Lastname"
git config --global user.email "you@mail.com"

confirm by cat ~/.gitconfig.

Then double check and make sure your Github account settings uses the same email.