Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Git

Branches

CREATE

Create a branch

git branch <branch-name>

Create a branch and switch to it

common

git checkout -b <branch-name> 

new

git switch -c <branch-name>
git branch --track <local-branch> origin/<remote-branch>
git branch <local-branch> origin/<remote-branch>
git checkout -b <local-branch> origin/<remote-branch>

If there is already a local one with the same name, then it will link to the remote one

git branch -f <local-branch> origin/<remote-branch>

If there is a local branch and you need to create a remote one with tracking

git push -u origin <branch-name>

If there are both local and remote branches and you need to make tracking

git branch -u origin/<remote-branch-name> <local-branch-name>

If you need to remove tracking

git branch --unset-upstream <branch-name>

MOVE

Move branch pointer to a different commit (destination-commit can be a branch name)

git reset --hard <destination-commit>
git branch –f <branch-name> <destination-commit>

DELETE

DELETE remote branch (remote-name usually origin)

git push -d <remote-name> <branch-name>

Don’t forget to do a git fetch --all --prune or git fetch --all -p on other machines after deleting the remote branch on the server. After deleting the local branch with git branch -d and deleting the remote branch with git push -d origin other machines may still have “obsolete tracking branches” (to see them do git branch -a). To get rid of these do git fetch --all --prune

DELETE local branch

git branch -d <branch-name>

The -D option is an alias for –delete –force, which deletes the branch “irrespective of its merged status”

git branch -D <branch-name>

DELETE local remote-tracking branch

git branch -dr <remote>/<branch>

long

git branch --delete --remotes <remote>/<branch>

RENAME

Rename current branch

git branch -m <branch_name>

Rename another branch

git branch -m <old_branch_name> <new_branch_name>

Rename branch on the remote

Push the local branch and reset the upstream branch

git push origin -u <new_branch_name>

Delete the remote branch

git push origin --delete <old_branch_name>

VIEW

View branches that was merged with the current branch

git branch --merged

View remote branches that was merged with the current branch

git branch -r --merged

View branches that was’t merged with the current branch

git branch --no-merged

PRUNE

git remote prune origin

short

git fetch -p

long

git fetch --prune

Changes

STAGE

Stage all changes

git add .

Stage changes in interactive mode

git add -i

Stage changes in patch mode

git add -p

UNSTAGE

Unstage some changes (MOVE from Index (staging area) to Workspace)

new

git restore --staged <file>

old

git reset <file>
git reset HEAD <file>

Unstage all changes

new

git restore --staged .

common

git reset

old

git reset HEAD

DELETE

Delete changes in Workspace

new

git restore <file>

old

git checkout -- <file>
git checkout <file>

Delete all changes in Workspace

new

git restore .

old

git checkout .

Delete all changes in Index and Workspace

git reset --hard
git reset --hard HEAD

REMOVE FROM GIT

Remove file from Git tracking but keep it on disk

git rm --cached <file_name>

Remove file from the git repository and from the local disk

git rm <file_name>

Commits

Make an empty commit

git commit --allow-empty -m "empty commit"

Undo the last commit and move changes to Working Directory (changes in staging area will also move to Working Directory) (–mixed by default)

git reset HEAD^

Undo the last commit and move changes to the Index

git reset --soft HEAD^

Undo the last commit and move changes to the Working Directory

git reset --mixed HEAD^

Undo the last commit and DELETE changes (uncommitted ones too)

git reset --hard HEAD^

CHERRY PICK

Copy one commit to current branch

git cherry-pick <SHA>

Copy range of commits to current branch

git cherry-pick <SHA>..<SHA>

Config

Open global config file for editing

git config --global --edit

Show global config file content in terminal

git config --global --list

Configure name and email

git config --global user.name "Your Name"
git config --global user.email test@email.com

Ignore

Line endings

The git config core.autocrlf command is used to change how Git handles line endings. It takes a single argument.

git config --global core.autocrlf input|true|false
autocrlfcommitcheckoutWhen to Use
inputCRLF → LF-Unix, MacOS
trueCRLF → LFLF → CRLFWindows
false--Single platform

Log

Filter

By number

git log -<number>

By date

git log --since=yyyy-mm-dd
git log --until="3 days ago"
git log --after=2.weeks --before=3.days

By author

git log --author="Name"

By commit message pattern

git log --grep="pattern"

By commits range

git log <SHA>..<SHA>

By file name (only shows commits that changed that file)

git log <file_name>

Decoration

git log --name-only --oneline

Remotes

Add remote

git remote add origin <repository_url>

Change remote

git remote set-url origin <repository_url>

View remote

View remote name

git remote

View remote name and url

git remote -v

View more info about remote

git remote show <remote_name>

Delete remote

git remote rm origin

SSH

Create SSH key

-t specifies the key type

-b specifies the key size (in bits)

-C for comment to help identify your ssh key (optional)

-f for the file name where ssh key get saved

ssh-keygen -t rsa -b 4096 -C "<your email>" -f $env:USERPROFILE/.ssh/<key_name>

Add SSH key to SSH Agent

Add SSH private key to SSH Agent

ssh-add $env:USERPROFILE/.ssh/<key_name>

Check if SSH Agent service is running

Get-Service ssh-agent

Stop SSH Agent service

Stop-Service ssh-agent

Start SSH Agent service

Start-Service ssh-agent

Add SSH public key to the Github

  • Copy content of <key_name>.pub
  • Goto Settings > SSH and GPG keys > New SSH Key
  • Paste your copied public key and give it a Title of your choice

Create SSH Config file and add Host Entries

If config file not already exists then create one ($env:USERPROFILE/.ssh/config)

Host github.com-<username>
  HostName github.com
  User git
  IdentityFile C:/Users/<user name>/.ssh/<key_name>
  IdentitiesOnly yes

Host github.com-<username>

  • This is the hostname for which these settings apply.
  • Every time you connect to this host via SSH, the following configuration will be applied.
  • You can use different settings for other hosts (for example, for other servers).

HostName github.com

  • Specifies the actual hostname to connect to.

User git

  • GitHub requires the user to be specified as git for all SSH connections.

IdentityFile C:/Users/<user name>/.ssh/<key_name>

  • Specifies the path to your private SSH key, which will be used to authenticate to GitHub.

IdentitiesOnly yes

  • Causes SSH to only use the keys specified in the configuration file (via IdentityFile) and ignore any other keys that may be loaded into the SSH agent.
  • This helps if you have multiple keys and want to use a specific key for a specific host.

Cloning existing repository or adding remote for the local one

Clone existing repository

git clone git@github.com-<username>:<username>/<repo_name>.git

Add remote to local repository

git remote add origin git@github.com-<username>:<username>/<repo_name>.git

Change remote in local repository

git remote set-url origin git@github.com-<username>:<username>/<repo_name>.git

Finally

Don’t forget to specify user.name and user.email in every repository freshly cloned or existing before.

git config user.name "Your name"
git config user.email "your@email.com"

If you set GPG signing globally you can remove this for the local repository

git config commit.gpgSign false

If you have new GPG key you can set it for the local repository

git config user.signingkey <new-gpg-key-id>

Useful

Commands

Show SSH key list

ssh-add -l

Delete SSH key from SSH Agent

ssh-add -d $env:USERPROFILE/.ssh/<key_name>

Check if your SSH client can connect to GitHub

ssh -T git@github.com

or more verbose

ssh -vT git@github.com

Stash

SAVE

new

git stash
git stash push
git stash push -m "message"

old

git stash save "message"

VIEW

git stash list

EJECT

Get content from stash (and delete from there)

git stash pop

Get content from stash (and leave it there)

git stash apply

DELETE

git stash drop

Tags

CREATE

Create lightweight tag

git tag <tag_name> <SHA>

Create annotated tag

git tag -am "message" <tag_name> <SHA>

Create a remote tag when local exists

git push origin <tag_name>

Push all local tags to remote

git push origin --tags

VIEW

View tag info

git show <tag_name>

View tags list

git tag -l

View tags list by pattern

git tag -l "pattern"

View tags list with first line of each annotation

git tag -n

DELETE

Delete local tag

git tag -d <tag_name>

Delete remote tag

git tag -d origin <tag_name>

Useful Git Commands

Show the branch on which a specific commit was originally created

git reflog show --all | FINDSTR <HASH>

Worktrees

CREATE

Create a worktree for an existing branch using the same name as the working directory

git worktree add path/to/folder/<existing-branch-name>

Create a worktree for an existing branch using a different name than the working directory

git worktree add path/to/folder/ <existing-branch-name>

Create a worktree with a new branch using the same name as the working directory

git worktree add -b <new-branch-name> path/to/folder/<new-branch-name>

Create a worktree with a new branch using a different name than the working directory

git worktree add -b <new-branch-name> path/to/folder/

VIEW

Show all worktrees

git worktree list

DELETE

Remove a worktree

git worktree remove path/to/folder/

or (link)

rm -rf path/to/worktree
git worktree prune
git branch -D <branch-name>

IDE

Visual Studio

Visual Studio Main Shortcuts

Editing

Ctrl+K,C – comment line
Ctrl+K,U – uncomment line
Ctrl+D – duplicate line
Ctrl+Shift+L – delete line without adding it to the clipboard
Alt+<Up/Down arrows> – move line up/down

Ctrl+K,F – format the selected block
Ctrl+K,D – format the entire file
Ctrl+K,E – clean up the code in the file (according to the rules you set, for example, removing unnecessary usings)

Ctrl+K,S – insert snippet (if, try, for block, etc.), or enclose the selected code in a block
Alt+Shift+<arrows> (Alt+<mouse selection>) – edit by columns
Ctrl+Alt+<place the cursor with the mouse> – multi-cursor input (edit in several places at once)

Ctrl+G – go to line
Ctrl+K,K – leave bookmark
Ctrl+K,N – go to next bookmark

Ctrl+, (Ctrl+T) – search by code in project
Ctrl+Q – search by IDE tools

F12 (Ctrl+<mouse click>) – go to definition
Alt+F12 – peek definition (definition hint in inline window)
Ctrl+F12 – go to implementation
Shift+F12 – find all references

Ctrl+Shift+space – method arguments hint
Ctrl+[,S – mark current file in solution explorer
Ctrl+; – search in solution explorer

Ctrl+M,O – collapse all methods to definitions
Ctrl+M,P – expand all methods
Ctrl+M,M – collapse/expand the current method
Ctrl+M,L – collapse/expand all outlining

Shift+Alt+. – Add the next matching text as a selection
Shift+Alt+; – Add all matching text as selections
Shift+Alt+, – Remove last selected occurrence
Shift+Alt+/ – Skip next matching occurrence

For ASP.NET
Ctrl+M,G – go from a controller method to a view or vice versa

Refactoring

Ctrl+. (Alt+Enter) – refactoring hints
Ctrl+R,R – rename
Ctrl+R,M – extract selected code to method
Ctrl+R,I – extract interface from class
Ctrl+R,V (Ctrl+R,O) – reorganize method parameters

Snippets

"prop",Tab,Tab – create a property
"ctor",Tab,Tab – create a constructor
Tab,Tab also works for other popular keywords (if, for, switch, etc.)

Debugging

F9 – create a breakpoint
Ctrl+Alt+B – open window with all breakpoints
Ctrl+Shift+F9 – delete all breakpoints

SQL

DML (Data Manipulation Language)

DML commands are used for storing, retrieving, modifying, and deleting data.

SELECT - retrieve data from a database

INSERT - insert data into a database

UPDATE - updates existing data within a database

DELETE - delete records from a database

DDL (Data Definition Language)

DDL commands are used for creating, modifying, and dropping the structure of database objects.

CREATE - create database objects such as tables and views

ALTER - alters the structure of the existing database

DROP - delete objects from the database

TRUNCATE - delete all rows from the database

DCL (Data Control Language)

DCL commands are used to implement access control on database objects.

GRANT - give a user access privileges on database objects

REVOKE - withdraw user privileges that were previously given using GRANT

Tutorials and docs

W3Schools SQL Tutotrial

SQLZoo

SQL Server

Data Types

String Data Types

Data typeDescriptionMax char lengthStorage
char(n)Fixed-length non-Unicode character data (n must be between 1 and 8000)8,000n bytes (uses one byte for each character)
varchar(n)Variable-length non-Unicode character data (n must be between 1 and 8000)8,000n bytes + 2 bytes
varchar(max)Variable-length non-Unicode character dataup to 2 GB
nchar(n)Fixed-length Unicode character data (n must be between 1 and 4000)4,0002 * n bytes (uses two bytes for each character)
nvarchar(n)Variable-length Unicode character data (n must be between 1 and 4000)4,0002 * n bytes + 2 bytes (uses two bytes for each character)
nvarchar(max)Variable-length Unicode character dataup to 2 GB
binary(n)Fixed-length binary data (n must be between 1 and 8000)8,000n bytes
varbinary(n)Variable-length binary data (n must be between 1 and 8000)8,000actual length of data entered + 2 bytes
varbinary(max)Variable-length binary data2GB

Numeric Data Types

Data typeDescriptionStorage
bitInteger that can be 0, 1, or NULL
tinyintAllows whole numbers from 0 to 2551 byte
smallintAllows whole numbers between -32,768 and 32,7672 bytes
intAllows whole numbers between -2,147,483,648 and 2,147,483,6474 bytes
bigintAllows whole numbers between -9,223,372,036,854,775,808 and 9,223,372,036,854,775,8078 bytes
decimal(p,s)Fixed precision and scale numbers.

Allows numbers from -10^38 +1 to 10^38 –1.

The p parameter indicates the maximum total number of digits that can be stored (both to the left and to the right of the decimal point). p must be a value from 1 to 38. Default is 18.

The s parameter indicates the maximum number of digits stored to the right of the decimal point. s must be a value from 0 to p. Default value is 0
5-17 bytes
numeric(p,s)Fixed precision and scale numbers.

Allows numbers from -10^38 +1 to 10^38 –1.

The p parameter indicates the maximum total number of digits that can be stored (both to the left and to the right of the decimal point). p must be a value from 1 to 38. Default is 18.

The s parameter indicates the maximum number of digits stored to the right of the decimal point. s must be a value from 0 to p. Default value is 0
5-17 bytes
smallmoneyMonetary data from -214,748.3648 to 214,748.36474 bytes
moneyMonetary data from -922,337,203,685,477.5808 to 922,337,203,685,477.58078 bytes
float(n)Floating precision number data from -1.79E + 308 to 1.79E + 308.

The n parameter indicates whether the field should hold 4 or 8 bytes. float(24) holds a 4-byte field and float(53) holds an 8-byte field. Default value of n is 53.
4 or 8 bytes
realFloating precision number data from -3.40E + 38 to 3.40E + 384 bytes

Date and Time Data Types

Data typeDescriptionStorage
datetimeFrom January 1, 1753 to December 31, 9999 with an accuracy of 3.33 milliseconds8 bytes
datetime2From January 1, 0001 to December 31, 9999 with an accuracy of 100 nanoseconds6-8 bytes
smalldatetimeFrom January 1, 1900 to June 6, 2079 with an accuracy of 1 minute4 bytes
dateStores a date only. From January 1, 0001 to December 31, 99993 bytes
timeStores a time only to an accuracy of 100 nanoseconds3-5 bytes
datetimeoffsetThe same as datetime2 with the addition of a time zone offset8-10 bytes
timestampStores a unique number that gets updated every time a row gets created or modified. The timestamp value is based upon an internal clock and does not correspond to real time. Each table may have only one timestamp variable

Other Data Types

Data typeDescription
sql_variantStores up to 8,000 bytes of data of various data types, except text, ntext, and timestamp
uniqueidentifierStores a globally unique identifier (GUID)
xmlStores XML formatted data. Maximum 2GB
cursorStores a reference to a cursor used for database operations
tableStores a result-set for later processing