The type of work I do requires me to switch between git branches constantly. Over time, I've built a list of shortcuts and customizations that made my life easier.
Read along if you want to customize your terminal output and copy & paste some useful shortcuts for docker and git.
Jazz up your terminal
Add an emoji on your user name and show the relative path of your directory
Turn this:
trisha @ /codewars $
Into this:
trishaš„ @ ~/projects/codewars $
- Copy and Paste into your .bash_profile and re-open your shell:
export PS1="\uš„ @ \w $ "
export CLICOLOR=1
export LSCOLORS=ExFxBxDxCxegedabagacad
PS1 will determine the display path. You can even add an emoji as seen above (š„).
CLICOLOR will determine the output color theme
LSCOLORS determines the background.
Terminal profiles and window arrangements
Use a terminal emulator (like iTerm2) to quickly launch profile configurations. Useful if you have a couple of full-stack projects you're working on and want to launch the application using a single command.
CTRL + SHIFT + R will quickly open a saved window arrangement with whatever profiles you configure it with. It'll look something like this:
^ Notice those tabs, eh?? Whatās so cool about it is that you can save full-stack repos in a window arrangement once and then switch tabs without needing to change directories constantly. What a time saver! :D
Pro-tip: You can also add a starting script on your saved profile. I typically add cd <file_path>; git fetch; git status; so when I open the profile, itās already in the correct directory and it tells me the status of my current branch.
iTerm2 link https://iterm2.com/index.html
Terminal color schemes
If you want your bash outputs to look better, try out iTerm2's themes. It makes a difference when you are reading the logs and error stacks.
- Color Schemes https://github.com/mbadolato/iTerm2-Color-Schemes
- My fav (dracula): https://github.com/mbadolato/iTerm2-Color-Schemes/blob/master/schemes/Dracula.itermcolors
You'll want to download the .txt file of your color scheme and then upload it on your iterm2 preferences < profiles < colors < color schemes:
Shortcuts / Aliases
Here's a list of useful git and docker aliases that I use daily. It's super helpful especially when your repos have submodules that you need to update daily.
# ----------------------
# Git Aliases
# ----------------------
alias upstream='git push --set-upstream origin'
alias ga='git add -A'
alias gb='git branch'
alias gbd='git branch --D '
alias gcm='git commit --message'
alias gco='git checkout'
alias gcob='git checkout -b'
alias gcod='git checkout development'
alias gd='git diff'
alias glg='git log --graph --oneline --decorate --all'
alias gp='git pull'
alias gs='git status'
alias gf='git fetch'
alias grh='git reset --hard'
# ----------------------
# Git Submodule ForEach Aliases
# ----------------------
alias gsf='git submodule foreach'
alias gcos='git submodule foreach git checkout'
alias gcods='git submodule foreach git checkout development'
alias gfs='git submodule foreach git fetch'
alias gss='git submodule foreach git status'
alias gbs='git submodule foreach git branch'
alias gps='git submodule foreach git pull'
alias grhs='git submodule foreach git reset --hard'
# ----------------------
# Docker Aliases
# ----------------------
alias dc='docker-compose'
alias dcb='docker-compose up --build'
alias dps='docker ps -a'
alias drm='docker container rm'
Top comments (8)
Great post
nice
We share a lot of the same aliases! I kept gp'ing when I meant to push, so I've changed them to gph and gpl and am making heavy use of positional parameters with most others. Thanks for the share!
I definitely didnāt want a shortcut for git push. Especially when I have access to push to the master branch at work. Imagine? š But I love how customizable shortcuts are. Beats having to type out the entire word when youāre short for time.
I am very happy I stumbled upon your post....iterm2 just changed my life. :) Thank you!
Iām so glad that helped you!! Happy coding :)
How do you, š„Trisha, edit your bash profile? I edit ~/.baschrc then source .bashrc but im curious if there is a better or easier way.
Hi Edwrd T! After creating my
.bash_profile, I usually just use vim to update it (vim .bash_profile). I think vim is the quickest way to edit single files. But here are other ways to edit the file in a mac os:cd ~/touch .bash_profileto create a new file..bash_profileon your IDE (open .bash_profile) or enteropen -e .bash_profileto open it in TextEdit.