Skip to content

Instantly share code, notes, and snippets.

@devcfgc
Last active January 24, 2019 13:24
Show Gist options
  • Save devcfgc/a541324d94c5a9324a6f3b96f5ecad14 to your computer and use it in GitHub Desktop.
Save devcfgc/a541324d94c5a9324a6f3b96f5ecad14 to your computer and use it in GitHub Desktop.
git most used commands

create branch from remote branch

  • git checkout -b branch-name origin/branch-name

remote

  • git remote add origin https://github.com/username/reponame.git
  • git remote -v
  • git branch --remote # to see all the branches from remote
  • git checkout branch-name # checkout a branch from remote
  • git remote rm destination # delete remote
  • git remote rename origin destination # change remote name from 'origin' to 'destination'

stash uncommited changes

  • git stash
  • git stash save "my_stash" # save it with a custom message
  • git stash save -u # stash uncommited and untracked changes
  • git stash list
  • git stash show -p stash@{1} # show stash changes
  • git stash apply
  • git stash apply stash@{0} # apply the staging changes at 0
  • git stash clear
  • git stash drop stash@{0} # remove the stashed work
  • git stash pop stash@{0} # apply the stashed work and remove it from the stash

squash

  • git rebase -i origin/master , then replace any the pick keyword with fixup from line 2 to the end of the commit list. afterwards save + exit., the force push : git push -f

overwrite from origin

  • git fetch --all
  • git reset --hard origin/master
  • git pull origin master

set upstream

  • git checkout -b mybranch
  • git push -u origin mybranch #(this is similar to git branch --set-upstream my_branch origin/my_branch)

review all remote branch

  • git branch -r
  • git branch -v -a

clear cache remote branch

  • git fetch --prune
  • git fetch --all --prune
  • git remote update --prune

remove local remote branch

  • git branch -d the_local_branch
  • git push origin :the_remote_branch

clean untracked files

  • git clean -n #show what will be deleted
  • git clean -fd #remove directories
  • git clean -fX #remove ignored files
  • git clean -fx #remove ignored and non-ignored files

configuration

  • git config --global color.ui auto
  • git config --global core.editor vim
  • git config --global help.autocorrect 1
  • git config --global color.ui auto
  • git config --global credential.helper cache

aliases

  • git config --global alias.co checkout
  • git config --global alias.br branch
  • git config --global alias.ci commit
  • git config --global alias.st status
  • git config --global alias.pr 'pull --rebase'
  • git config --global alias.prc 'rebase --continue'
  • git config --global alias.pra 'rebase --abort'
  • git config --global alias.pf 'push -f'
  • git config --global alias.fa 'fetch --all'
  • git config --global alias.hist 'log --oneline --decorate --graph'
  • git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"

git revert - rollback to a previous state

  • git reset --hard df9cf323 && git clean -f
@aasier
Copy link

aasier commented Jul 23, 2018

find /path/to/files* -mtime +5 -exec rm {} ; 💃

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