July 10, 2016

Useful shortcuts and commands

A documentation of my most used Visual Studio keyboard shortcut commands at work and git commands - I'm sure there are many more useful shortcuts/commands I could be using but here are the ones I use almost daily for now:

Visual Studio

Ctrl + G - Go to line number
Ctrl + . - Autocompletes a lot of stuff (this is our principal dev's favorite shortcut so that means something)
Ctrl + L - Cut line (delete and copy into clipboard)
Ctrl + K, Ctrl + C - Comment selected block of code
Ctrl + K, Ctrl + U - Uncomment selected block of code
Ctrl + R, Ctrl + R - Rename a variable
Ctrl + K - Toggle bookmark
Ctrl + K, Ctrl + W - Open bookmark window
Alt + (up arrow OR down arrow) - Moves current line of code up or down
Ctrl + Shift + B - Builds solution
Alt + B, U - Build current project
Ctrl + Shift + F - Find/replace in entire solution, project, or document
Ctrl + 0, E - Navigate to Team Explorer -> Branches
Ctrl + 0, G - Navigate to Team Explorer -> View changes in workspace
Ctrl + F12 - View implementation definition (just F12 will take you to interface definition which can be annoying)
Ctrl + [, S - Sync Solution Explorer with active document
Ctrl + ; - Search Solution Explorer for file name

Not including basic things like copy/paste, selection of entire word/line, move cursor to end/beginning of line because those are not VS-specific and most programmers already know about those

Git

git checkout, pull, add, commit, push - because duh
git stash - saves your workspace and moves it out of the way so you can checkout another branch
git stash pop - puts what you stashed back into your workspace
git push -u origin <branch> - publishes your local branch
git log --pretty=format:"%h, %an - %ar: %s" - logs the most recent commits in one line, where %h is the commit hash, %an is author name, %ar is author date (relative), %s is the commit message (subject)
git rebase -i HEAD~N - squash commits, where N is the number of commits you'd like to squash
git reset --hard origin/master - what i use when i screw up my branch and have to set it back to remote
git reset --soft HEAD^ - undoes last commit and puts changed files back into workspace.  I use this (in conjunction with previous command) to glean a comprehensive view of my entire changes before I submit for PR
git rebase master - rebase master onto local branch, after you have pulled from master
git diff --name-status branch_1 branch_2 - view diff of two branches, but only the file names that contain the diff
git diff branch_1 branch_2 - view details of diff
git push origin <branch name> -f - force pushes to local branch (which is necessary after having pushed your branch and then rebased, commonly happens during code review).  I only use force push on my own local branch.
git fetch origin, git reset --hard origin/master - set branch to exactly match remote

Interactive git cheat sheet - A neat little interactive diagram of how each stage of git interacts with each other

Random

Ctrl + Shift + T - (Chrome) Reopen closed tab
Ctrl + J - (Chrome) Open list of downloads
Ctrl + U - (Fiddler) Copy URL
R - (Fiddler) Reissue request
Ctrl + 2 - (Fiddler) Mark request to blue.  Can also use different numbers for other colors
Ctrl + Shift + L - (VsCode) Selects all words equivalent to the current one highlighted, and performs the same action on all.  Very useful for parsing stack traces.