Home > git reference

git reference

Tags:  

(another good quick reference I've found is Git - SVN Crash Course and Git_Guide (sourcemage) )

To setup git for windows... see gitcasts.com Git on Windows
  1. download and install msysGit from http://git.or.cz/
To setup github account
  1. sign up for account
  2. create ssh public-private key which is needed to push changes to git hub...
  3. > ssh-keygen -C 'emailaddress@host' -t rsa
  4. key is stored in %HOME%\.ssh directory on windows
  5. copy and paste public key to github
To setup git user name and email
  1. > git config --global user.name 'Greg Houston'
  2. > git config --global user.emal 'my_emal@host'
To see global configuration
  1. > cat ~/.gitconfig

To start a new project
  1. change to project root directory
  2. > git init 
  3. the command above creates the .git directory
To set a list of files to ignore
  1. create .gitignore in the project directory
  2. in .gitignore list files or glob patterns to ignore (can use ** and * and ?, e.g. tmp/**/*)
To see files in git repository
  1. > git ls-files
To see status of files/commits/staged/etc
  1. > git status
To remove an existing file
  1. use git rm instead of the operating system's delete or rm...
  2. > git rm filename_or_pattern
  3. > git commit -m "description of changes"
To add and commit files
  1. first add files to the index of files to commit...
  2. > git add filename_or_pattern
  3. added files are called "staged" because they are ready to be committed (git add does put an object to the git repository)
  4. next commit the changes, use -m to provide a comment
  5. > git commit -m "description of changes"
  6. you must add all changed files before commit will do anything.
To automatically add and commit modified files
  1. > git commit -a -m "description of changes"
To see information about commits
  1. > git log
To see commits with diff...
  1. > git log -p
To clone repository (ex. from github)
  1. > git clone git://github.com/ghouston/color-console.git
To push changes to a remote repository
  • git gui will just sit there, i guess it is waiting on the passphrase
  1. > git push git@github.com:ghouston/color-console.git master
  2. where "master" is the name of the branch
  3. it will prompt for the ssh key's passphrase

To rename a file

  • to avoid loosing history information, you need to commit the rename before modifying the renamed file!
  1. > git mv oldfilename newfilename
  2. commit the newfilename before modifying it!

To create a branch

  1. > git branch dev

To list branches (* by working branch)

  1. > git branch

To select a branch to work with

  1. > git checkout dev
  2. or (the following is works best on Ubuntu)
  3. > git checkout -b local_branch_name --track remote_branch_name

To diff changes between branches

  1. > git diff dev master

To update branch with changes from base

  1. > git checkout dev
  2. > git rebase master

To push branch to remote

  1. > git push git@github.com:ghouston/tofuhash.git dev

To merge branches (e.g. dev into master)

  1. > git checkout master
  2. > git merge dev

To work on an upstream branch that isn't master (next in this example)

  1. git checkout --track -b next origin/next
  2. git pull

For more details see http://github.com/guides/git-cheat-sheet



 RSS of this page