Hao

Git Command Cheatsheet

Set push.default

git config --global push.default current

for more info

How to push all local branches to remote


for remote in `git branch -r | grep -v master `; do git checkout --track $remote ; done
git push --all

How to show the log in a graph

git log --graph --oneline

How to look up the first few commits

git log --pretty=oneline  master | tail -1

Reset

git reset --hard xxxx

Rebase commits

git rebase -i HEAD~2

git push authentication failure due to two-factor check

git remote -v && git remote remove origin 
git remote add origin git@github.com:user/repo.git  

Delete multiple branches by one command line

git branch | grep 'gnip-' | xargs git br -D

Use git bisect to find the problematic commits

  1. git bisect good <goo_commit>
  2. then mark each step, git bisect good or git bisect bad

Sync local fork

  1. git remote -v check whether we have an upstream or not
  2. git remote add upstream <origin_git_url> add an upstream pointing to the origin repo
  3. git fetch upstream
  4. git merge upstream/master

Show origin remote

git remote show origin

Update the local branch

git branch -D the_branch then git checkout --track origin/the_branch

Remove untracked local files

git clean -f

Delete a file

git reset HEAD [a file]

Show git remote branches

git branch -a | grep remotes/*

Amend the git commit message

git commit --amend -m "New commit message"

push the branch to the server

git push origin <branch_name>

pull the changes from the master

git pull --rebase

show multiple changes (3 changes)

git format-patch --stdout HEAD~3

Reset commit

  • git reset --soft HEAD^
  • git stash

About merge

git merge <branch_name>

Remove git branch

  • git br -d <branch_name> for local
  • git push origin <branch_name> if want to apply to the remote
Posted May 25, 2016
READ THIS NEXT:

A Readlist about Web Performance

Good articles about runtime web performance: High Level Explain High Performance Animations Concept WebFundamentals About Performance Performance Checklist Discussion about debouncing scroll...


blog comments powered byDisqus