Skip to content

Instantly share code, notes, and snippets.

@jdbevan
Last active August 29, 2015 14:13
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 jdbevan/7123ad934da58ab09c49 to your computer and use it in GitHub Desktop.
Save jdbevan/7123ad934da58ab09c49 to your computer and use it in GitHub Desktop.
Frequently used Git commands
# Update knowledge of remote branches
git fetch
# Create a new branch, starting at the existing checkout out point
git checkout -b {some branch name}
# Interactively add unstaged changes to staging
git add -p
# Un-add a file from staging
git reset HEAD {filename}
# View staged changes (to review before commit)
git diff --staged
# Show commit log
git log
# Show graphed commit log
git log --oneline --all --graph --decorate
# Interactively rebase (change) the last 7 commits
# !! Don't rebase pushed commits !!
git rebase -i HEAD~7
# Unstage all changes for a commit while rebasing, useful for splitting a commit apart
git reset HEAD~
# Change the source of the current branch to the HEAD of master
git rebase master
# Rebase local changes against un-pulled remote changes
git fetch
git rebase origin/my-awesome-branch
# Rename local branch
git branch -m old-name new-name
# Delete the remote branch with the old name:
git push origin :old-name
# Re-create the remote branch with the new name:
git push origin new-name
# Undo a commit, keeping files in working directory
git reset --soft HEAD~1
# Change URL for remote
git remote set-url {some remote} {new git url}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment