Git Navigation Commands
A brief cheat sheet for navigating around the terminal.
How to navigate in out and around your directories after you have installed git on your machine:
ls — stands for list. What it does, is it lists any files or folders in the directory you are currently in. For example, If I open up the terminal on my macbook, and type in this command first thing, I get folders like downloads, documents, and applications. It shows me the folders I can get into from where I am at the root of the OS.
cd — stands for change directory. This allows you to either move up or down within your computers directories. To move up, you have to specify the folder you want to get into. for example:
Now you can see above that “Downloads” has moved from the right side of the %-sign to the left, which means I am now in that folder, and if I want to check its contents, I could type in “ls” to see what files are in that folder.
If you want to navigate down /backwards to the previous folder, you simply need to type in “cd ..” OR if you want to go to the root folder you can simply type in “cd” all by itself to go all the way back.
mkdir — Stands for make directory and this is used to make a new folder within the folder you are in. So if I am in my Downloads folder and I type mkdir Sample_Folder, this is what happens:
Be sure not to include spaces in the naming of the new folder, and same goes for files you create, which is what is next.
touch — This is how you create a new file. be sure to add the file type like .js .index etc. Be sure you are in the folder you want to be in when you create the file.
mv currentfilename newfilename — This command changes the name of your file or folder. The structure of this command is pretty simple you first write down the current name and the new name and it will automatically update after you hit ENTER.
mv filename ./directory name — This command moves your selected file or folder to another folder. This specific command will work if the folder you want to move a file into is in the same directory. For example after I put this command in, you will notice catpaws.js is gone because I moved it into the newNew folder.
And if I click into the newNew folder you will find the catpaws.js file:
If I wanted to move this file back to the previous folder, you need to cd into that newNew folder in your terminal, and THEN you will put in the following command with two periods ../
BUT look, I made a mistake thats worth noting, if you look above, the catpaws.js file name changed after I entered that last command. The reason that happened is because there was no SampleFolder to be found when it moved, so it thinks that was a file I wanted to create after the move to a different directory. I should have typed in Sample_Folder. So that’s a good mistake to note.
rm filename — This is how you can delete files
rm -R foldername — This is how you can delete folders
I hope this helps someone! :)
World Famous Coding Dad Joke #331:
Question: Why do single people get nervous about git?
Answer: They are scared to commit.
Follow me on Twitter @DVazDev