November 23, 2016 - VitoMd and the Evil Machine

My Console and github cheatsheets

I will share some useful commands, cheatsheets and tips that I use to speed up a little my development process.

Github

I use alias for the most used commands in github. So, the first thing I do when I´m in a new computer is this:

git config --global alias.co checkout
git config --global alias.s status

Here is a list of github commands that are not used often but are really useful:

// diff with last commit
git diff HEAD^ HEAD

// diff with specific commit
git diff commit_id HEAD

// remove last commit soft (don´t delete code)
git reset --soft HEAD~

// remove last commit hard (delete code)
git reset --hard HEAD~

// point to the remote branch
git reset --hard upstream/development

// move to last used branch
git co -

// search commit local or remote
git branch --contains commitid
git branch -r --contains commitid

//Search for an added or removed word (or string)
git log -Sword    // string
git log -Gword    // regular expression

//show changed files in a commit
git diff-tree --no-commit-id --name-only -r commitid

//show last commited files
git show --name-only

Console

Here are some useful commands to use in the console/terminal:

ctrl+a     // go to start of the line
ctrl+e     // go the end of the line
ctrl+u     // clean line
ctrl+w     // delete a word
alt+click  // goto that exact place in the text
ctrl+l     // clean screen (same as clear)
ctrl+d     // close terminal (same as exit)

Alias

You can add alias to your .bash_profile, just edit the file and then do . .bash_profile to reload it. Use the alias command to check the alias in your system and which name1 name2 to check if name1 and name2 are already defined functions in your system.

Some useful alias related to github and rails and javascript development. The first is my favourite, to get the current branch name.

alias cb='git rev-parse --abbrev-ref HEAD'
alias rdm='rake db:migrate'
alias brc='bundle exec rails c'
alias bi='bundle install'
alias ni='npm install'
alias gpud='git pull upstream development:development'

Bonus

Sometimes I forgot an alias name, so another useful tool is clipMenu (www.clipmenu.com for mac) its a clipboard manager that keep the history of copied items and also it can store snippets or long commands that you use frequently. I just do cmd+ctrl+v to select from the list what I want to paste.

Share this post on Twitter

Comments