Skip to content

Instantly share code, notes, and snippets.

@wutangpaul
Last active March 15, 2017 14:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wutangpaul/89024d3bcaec657428458ce943e98cd0 to your computer and use it in GitHub Desktop.
Save wutangpaul/89024d3bcaec657428458ce943e98cd0 to your computer and use it in GitHub Desktop.
Useful git commands

Create a new local git repository in current directory

git init

Check out (and switch to) remote branch

git checkout <remote branch name>

Update current branch

git pull

Add all files in current directory to next commit

git add .

Commit current set of changes

git commit -a -m "<your commit message>"

Push your commit to remote

git push

Display list of all available branches, both local and remote

git branch -a

Clean up list of remote branches

git remote prune origin

Delete local branches that no longer exist on remote

git branch -r | awk '{print $1}' | egrep -v -f /dev/fd/0 <(git branch -vv | grep origin) | awk '{print $1}' | xargs git branch -d

Stash your current set of (uncommited) changes and revert to HEAD

git stash

Display log of previous commits

git log

Compare local changes to what's on remote

git diff
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment