Skip to content

Instantly share code, notes, and snippets.

@jxu
Last active December 4, 2024 18:56
Show Gist options
  • Save jxu/665527ba8801099e8e57904d5a25b8df to your computer and use it in GitHub Desktop.
Save jxu/665527ba8801099e8e57904d5a25b8df to your computer and use it in GitHub Desktop.
Useful git commands
# push to new github repo
git remote add origin [email protected]:jxu/repo.git # use set-url if already set
git push -u origin master
# check out a remote branch
git fetch
git branch -v -a # list all branches
git switch branchname
# change remote a branch is tracking
git branch branchname -u origin/branchname
# Throw away all changes, staged and unstaged
git reset --hard
git clean -fd # remove untracked files
# reset master to origin/master
git checkout -C master origin/master
# delete branch
git branch -d branchname # local
git push -d origin branchname # remote
# rename branch
git branch -m oldname newname
# file diffs
git diff HEAD # colored diff with last committed
git diff --word-diff=color # diff by word instead of line
git diff --stat # show lines changed
# easy to read log, one line per commit
git log -all --oneline --graph
# show changed files per commit
git log --stat
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment