Sunday 15 December 2013

Useful Git Commands

I've made several posts about git as I was learning to use it. This is a list of all the useful commands I found in the form of a cheat sheet.
Anything surrounded by < > should be replaced with an arguement e.g. git checkout <branch> becomes git checkout branchname.

git diff HEAD^ filename: show differences between current file and repo file
git diff HEAD^^:
git diff HEAD~1 filename: where 'git reflog HEAD' lists possible commits

git branch -d <branch>: delete branch
git checkout <branch>: switch to branch
git checkout -b <branch>: create and use a new branch
git reflog HEAD: lists all commits that HEAD has pointed to (accessible by HEAD~n)
git fetch origin <remotebranch>:<localbranch>: create a local branch from a remote branch
git merge <branch>: merge a branch into the currently checked out branch
git log: list all commits (q to quit)
git merge --abort

git stash
git pull: pull down the latest version from origin
git push origin master: push the local master branch to the remote 'origin'
git remote add <name> <url>: e.g. git remote add origin https://user@github.com/user/repo.git
git remote set-url origin https://yourusername@github.com/user/repo.git: set origin url to your username, then git push will ask you for a password. Useful if you did a read only git clone.
git stash apply stash@{0}



No comments:

Post a Comment