VS Code Configuration & Set-up

Configuration#

Remote SSH#

Host machine
    Hostname machine.com
    User user_name
    IdentityFile path/to/ssh/key

Remote SSH - SSH Tunnel#

Host tunnel_machine
    Hostname machine.com
    User user_name
    IdentityFile path/to/ssh/key

Host machine_after_tunnel
    Hostname machine_after_tunnel.com
    User user_name
    IdentityFile path/to/ssh/key
    ForwardAgent yes
    ProxyJump tunnel_machine

PC Configuration#

Authorize your windows local machine to connect to remote machine.

$USER_AT_HOST="your-user-name-on-host@hostname"
$PUBKEYPATH="$HOME\.ssh\id_ed25519.pub"

$pubKey=(Get-Content "$PUBKEYPATH" | Out-String); ssh "$USER_AT_HOST" "mkdir -p ~/.ssh && chmod 700 ~/.ssh && echo '${pubKey}' >> ~/.ssh/authorized_keys && chmod 600 ~/.ssh/authorized_keys"

Verify that the authorized_keys file in the .ssh folder for your remote user on the SSH host is owned by you and no other user has permission to access it.

Git commands I often use

Add#

# only add files with .scala extension
git ls-files [path] | grep '\.scala$' | xargs git add
git stash --keep-index

Log & History#

# compact, visual branch graph
git log --oneline --graph --decorate --all

# search commits by message
git log --grep="keyword"

# show changes introduced by each commit
git log -p --follow -- path/to/file

# who changed what line
git blame -L 10,20 file.txt

Diff#

# diff staged changes (what's about to be committed)
git diff --staged

# diff between two branches
git diff main..feature-branch

Undo / Fix#

# undo last commit but keep changes staged
git reset --soft HEAD~1

# amend last commit (message or content)
git commit --amend --no-edit

# discard changes in a file
git checkout -- file.txt

# recover a dropped stash or deleted commit
git reflog

Branches#

# delete remote branch
git push origin --delete branch-name

# rename current branch
git branch -m new-name

# show which branch a commit is in
git branch --contains <commit-hash>

Stash#

# stash with a name
git stash push -m "wip: auth refactor"

# apply specific stash
git stash apply stash@{2}

# list stashes
git stash list

Productivity#

# find which commit introduced a bug (binary search)
git bisect start
git bisect bad        # current is broken
git bisect good v1.0  # last known good

# apply a single commit from another branch
git cherry-pick <commit-hash>

# rebase interactively (squash, reorder, edit)
git rebase -i HEAD~3