Skip to content

Instantly share code, notes, and snippets.

@taktran
Created November 13, 2011 11:17
Show Gist options
  • Save taktran/1361994 to your computer and use it in GitHub Desktop.
Save taktran/1361994 to your computer and use it in GitHub Desktop.
Git cheatsheet

Git cheatsheet

An incomplete just-in-time cheatsheet for git. Things are added as required.

Add remote repository

To add an existing repo to a remote repo

  1. For github/bitbucket, create repo there first, and get git address, eg

    git@bitbucket.org:taktran/[some project].git
    
  2. Set up remote branch

    git remote add origin git@bitbucket.org:taktran/[some project].git
    
  3. Push to origin

    git push origin master
    
  4. To configure master to track the remote branch

    git config branch.master.remote origin
    git config branch.master.merge refs/heads/master
    
  5. Now you can just do

    git push
    

Merging

Throwing away a dirty merge

git reset --hard HEAD

Throwing away a committed merge

git reset --hard ORIG_HEAD

Squash a commit, go into the branch you want to merge to eg, for merging feature branch to master, git checkout master, then:

# Note that the message does not get used if there are no conflicts.
git merge --squash -m "Some msg" feature

Push branch to remote repo

  1. Create remote branch

    git push origin HEAD:refs/heads/[new_branch]
    git fetch origin     # Update everything
    git branch -r        # Lists all remote branches
    
    
  2. Start tracking new branch

    git checkout --track -b [new_branch] origin/[new_branch]
    
  3. Update everything with git pull

To delete a remote branch

git push origin :new_branch      # Deletes the remote branch
git branch -d new_branch         # Deletes the local branch

Diffing

Can diff between different tags. -- represents current

git diff 0.5.1 -- models/*

Heroku

  1. Create app

    heroku create --stack cedar
    
  2. Deploy code

    git push heroku master
    
  3. Rename app

    heroku rename [new name]
    

Or to add heroku to an existing folder:

git remote add heroku git@heroku.com:[project name].git

Useful commands

For multiple deployment locations, use --app [project name] flag to run commands

heroku ps         # Check processes
heroku logs
heroku run console

heroku run rake -T
heroku run rake db:migrate
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment