29. Stash
DEMO
Use git stash when you want to record the current state of the
working directory and the index, but want to go back to a clean
working directory.
Personally, I don’t use stash that much, instead of this I commit
current changes temporarily and rebase or reset later.
32. Some problematic cases
● You have committed a change (or changes) to a branch, but the commit(s)
should be in another branch.
○ The branch history is only in LOCAL
○ The branch history is already pushed to REMOTE
● You want to split up current branch state into two or three different branches.
○ The branch history is only in LOCAL
○ The branch history is already pushed to REMOTE
38. Cheat sheet
If you want to use alias for git, install zsh and set plugin for git.
e.g. ‘ga’ instead of ‘git add’, ‘gp’ for ‘git push’...,
● Install ZSH: https://github.com/robbyrussell/oh-my-zsh/wiki/Installing-ZSH
● Install Oh-My-ZSH: sh -c "$(curl -fsSL
https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/inst
all.sh)"
● Set plugin: https://github.com/robbyrussell/oh-my-zsh#plugins
If you want to add additional alias for yourself.
● vi ~/.zshrc
● Put this on any line (usually the last line)
○ alias some_shorten_command=”some full command”
○ E.g. alias gitr="git branch --merged | egrep -v "(^*|master|dev)" | xargs git branch -d"
■ Then you can use `gitr` on your terminal.
39. Cheat sheet
Description Command using alias Full command
Add changed files to staging ga . git add .
Commit staged files with message gc -m 'some message' git commit -m 'some message'
Add changed files to staging and commit with
message. but newly created files are not affected
gc -a -m 'some message' git commit -a -m 'some message'
Create branch gco -b 'branch name' git checkout -b 'branch name'
Change branch gco 'branch name' git checkout 'branch name'
Reset last 2 commits, but keeping the changes N/A git reset --soft HEAD~2
Pull the latest changes of a branch gco 'branch name'
gl
gco 'branch name'
git pull
Push the commits to remote server gp git push
Change to master branch gcm git checkout master
Merge master branch of remote server to current
branch
gmom git merge origin/master
Clean up already merged branches gcm
gitr **
** if you added alias of this command by the
instruction on slide 38, you can use the short
command.
git checkout master
git branch --merged | egrep -v "(^*|master|dev)" |
xargs git branch -d