The "OhSnap!" series explores bite-sized tips that you can apply today.
Here is a list of some helpful terminal and git commands for your viewing pleasure and my own future reference. 😉
Working With Spaces
cd Class\ Work
cd 'Class Work'
Use a backslash (
\) to make "Class\ Work" equal "Class Work”.
Encapsulate the phrase with quote marks to preserve spaces between words.
Open project folder in VS Code
cd my-project-folder-name code .
Only show directories
ls -d */
Clear the terminal
cmd + k
Go back to the main directory
Create a file
Create a folder/directory
Removes a file
Remove a folder
rm -r my-project
-r stands for “recursive”. It means to delete this thing and everything in it.
Copy a file/folder
cp img images
The first value is the original file/folder and the second value is what it is copied as.
Rename a file/folder name
mv old-name.html new-name.html
The first value is the original file/folder name and the second value is the new name.
Open folder in Finder
Getting unstuck from hard-to-exit terminal screens
shift + z shift + z
Show available local branches
Create new branch
git checkout -b feature-1
checkoutmoves to the new branch
-bcreates a new branch
feature-1name for branch
Push local branch to remote
git push origin feature-1
Switch to a new branch
git checkout main
Merge changes from one branch to another
git merge master
- Navigate to the branch you want to work in
- After the
mergekeyword, specify the branch that has the changes to be merged from
Grab all remote branches without merging
git fetch --all
Reset the local master with the remote version
git reset --hard origin/master
Remove non-committed changes from all branches and master since
git checkout -f
View differences between commits
To leave this view hit
Q on the keyboard
Thumbnail designed with Figma
Top comments (3)
Couple of tips:
cmd + kis going to be specific to MacOS.
ctrl + lwill work on pretty much any terminal emulator and is also often bound to things like "redraw" in apps as well.
cd ~will take you to your home directory, but also so will
cdon its own.
Opening the current directory in apps, like with
open .is the same as passing the complete current path.
openis a Mac-specific (in this case) program which dispatches the path parameter to whatever application is associated with "folder" (again, in this case). On Linux you'd do something like
xdg-openif you have a GUI, or even something else depending on your configuration. On Windows I suspect you're SOL.
This means if you have something associated with
.jsfiles in your GUI (e.g. Finder) then
open foo.jswill launch that application, regardless of what it is. In that case,
openis a tiny bit easier because you can share code using it with others and it'll work even if they use something else like Sublime.
I have a whole rant about using touch to create files.
I'm guessing you have
lessas your pager for git diffs. It doesn't have to be that way though, and even if you do there's a good chance it's not called if there's nothing to diff!
What do you mean by this? What terminal screens are getting stuck? The only time I know ZZ as a shortcut it's an alternative way to save and exit Vim.
Thanks for leaving feedback and additional explanations. Regarding your question at the end, I do believe the screen was a VIM editor. It sometimes comes up when I am working with git.
If you're using Vim to edit git commit messages and don't want to, I think there's a git config setting. Failing that, I imagine setting something like;
in your shell config would let you use VS Code instead (or whatever you want)