Skip to content

Instantly share code, notes, and snippets.

@gabrieljoelc
Last active December 15, 2015 03:58
Show Gist options
  • Save gabrieljoelc/5197732 to your computer and use it in GitHub Desktop.
Save gabrieljoelc/5197732 to your computer and use it in GitHub Desktop.
Common git commands for the noob (me).
# commit
git add filenametocommit.cs
git commit -m 'Commit comment'
# add remote url
git remote add origin git://url.here
# change remote url
git remote set-url origin git://new.url.here
#undo unstaged specific file
git checkout path/to/file/to/revert
#undo all unstaged files
git checkout -- .
#undo staged files before commit
git reset filenametocommit.cs
git add . # add to index only files created or modified and not those deleted
git add -u # add to index only files modified or deleted and not those created
git add -A # do both operation at once, add to index all files
#remove files from repo but not file system
git rm --cached mylogfile.log
#rename a branch
git branch -m old_branch new_branch
#delete a branch
git branch -d the_local_branch
# shows one commit per line, and decorates with branch names (here's a good resource http://think-like-a-git.net/sections/graphs-and-git/visualizing-your-git-repository.html)
git log --graph --decorate --oneline
# Merge specific files (not commits) from one branch to another see http://jasonrudolph.com/blog/2009/02/25/git-tip-how-to-merge-specific-files-from-another-branch/
git branch target_branch
git checkout source_branch app/models/avatar.rb db/migrate/20090223104419_create_avatars.rb test/unit/models/avatar_test.rb test/functional/models/avatar_test.rb
$ git commit -m "'Merge' avatar code from 'target_branch' source_branch"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment