There’s so much to know, and scratching the surface was very much like a bad date. But instead of glancing to my phone waiting for a miracle to get me out of the situation, I was glancing to and from tutorials typing carefully as I was learning how the command line likes to speak.
The Command Line was the topic I met with the most resistance in my coding journey thus far. After all, why learn the Command Line when all of the tasks can be done manually (queue nails on a chalk board)? The user interface is bland, you can’t “build” anything with it, and memorizing commands sounds so boring to me. However, while I was building my first project, I faced the resistance head on and began getting comfortable with some commands that have smoothed out my workflow and I now use every day.
Command Line Basics
The Terminal application on the Mac is where you can have some command line fun. Basically the terminal is an interface you can interact with and displays information about your computer— the files, folders, users etc.
Creating folders from the command line is important because it helps you stay organized. When I began working on my project, I had to create a path to store it that would make sense. From my Home folder on my user account for my mac, I created a folder called Development by typing:
This is where all my code will be stored.
Then, I went into the folder I had just created by typing:
In order to create two more folders, because not all code will be for projects:
mkdir projects; mkdir labs
I’m going to have several projects and many labs, so it’s best to keep these separate. Also, this is how you can type several commands on one line separating each with a ; so you don’t have to press enter each time you want to run a task!
I didn’t have to do this while I was building my project, but here is how to add a file, remove a file, and remove a directory:
touch kittens.rb; rm kittens.rb; rmdir all-the-kittens
Back to our regularly scheduled programming…
Next, I had to figure out how to interact with my GitHub account through the command line so my project could go from being stored locally to the interwebs for the world to see (and so I could also download later should anything happen to my local files or if I needed to retract to a previous version of my project…. anyways…)!
First I created a new repository on GitHub which I named after my local project, yay naming convention!
Then, I went back to my terminal to initialize my local directory as a GitHub repository:
I then made sure my new local repository had all the files from my project:
git add .
Next, I had to commit (think prepare to publish) the files I’ve staged in my local repository:
git commit -m"First commit"
Then, I had to set up the path where my local repository will be “published” or pushed. It will be pushed to the repository url I just created on GitHub. I copied and pasted “firstname.lastname@example.org:mccarronmollye/codenewbiepod.git” per guidance from GitHub, where they explained how to connect your local repository to GitHub if you have started the project locally.
(Note: The breakdown of the path was essentially “email@example.com:username/project.git”)
git remote add origin firstname.lastname@example.org:mccarronmollye/codenewbiepod.git
And now the moment we’ve all been waiting for, I get to push my project to GitHub!
git push -u origin master
Say I wanted to work on my project from my friend’s laptop. All I would have to do is go to my repository on my GitHub account, click ‘Clone or Download’, make sure I’m using SSH key, and click the clipboard symbol in order to copy the repository path.
Then, in my terminal I would type:
git clone 'email@example.com:mccarronmollye/codenewbiepod.git'
In order to get the project onto my machine so I could work on it! Voila!
When I’m finished I would run through the following (explained above) in order to have the most up to date version on GitHub:
git add . git commit -m 'list out some updates you have made' git push
Note: adding a descriptive message is very important so you can know at a high level what kind of changes you’ve made or features you built.
I can now say I know the Command Line a bit better now, and will continue to make the effort to learn its features! What are some commands you use on a daily basis that aren’t mentioned above? I’d love to know!