A Morning in a Front End Developer’s Mac Terminal

 

Learn some of the MAC’s operating system and git terminal commands a Front End Developer uses on a workday. If you want to read the Spanish version of this story, you can find it here.

Plays Fresh Prince of Bel-Air intro song: “🎵Now, this is a story all about how this Front End Developer turns her terminal upside down. And I’d like to take a minute, sit right there. I’ll tell you how I use the Mac terminal throughout the day to be clear. 🎵

A Slack message popped up. “Can you please check out what is causing this bug? I am having a meeting with an important client at 3 pm today, and it would be nice to show this feature” it read.

So I searched for my “typing furiously” playlist. Wrapped my hair in a bun. Took a sip of coffee. Hit the Spotlight Search using the shortcut [command + spacebar ] and searched for the to access my Mac Operative System terminal command line.

New Mac terminal window
Open Terminal

Mac Terminal Commands

“Where am I?” It sounded philosophical when I thought it. But actually, I needed to enter the command [ pwd ] to print the working directory in my Mac terminal. [ pwd ] is like a Google Maps for archives. It shows the directory where I am at.

Terminal with [pwd] command print
Current directory

“Great! I am in the directory I want to be in. But, I do not remember the directory I want to navigate to,” I thought. Instantly, I answered myself with: “That’s where [ ls ] (List Directory Content) comes in handy.”

[ ls ] shows the content inside the current directory.

Mac terminal with [ls] command print
Folders inside /Users/yari directory

My thoughts continued: “I remembered in which directory I cloned the project. Now, I need to [ cd ](change directory) to get to the project’s local repository.”

I went ahead and started to change the directory. Entering [ cd ] followed by the subsequent directory names I want to navigate into. Separating each directory name with a forward slash [ / ].

Change directory command [cd]
Change directory to src file

Until I found myself inside the src (source) directory. “Wait! Is package.json inside the src file? Let me [ ls ] this thing!” I continued.

Terminal inside src directory
The content inside the src directory

“Nope, there is no way I can run the web app from this directory,” I said to myself. This time, it was out loud.

“Shhhhhh, I am in a meeting!” said Ramona, my coworker.

Whispering: “I need to go up a level in the directory, but how?”

That’s where the dots on the command line came in handy: [ cd .. ]. Two dots after cd means to go one level up the directory tree.

terminal command [cd ..] to go up a level in the directory
[ cd .. ] goes one level up the directory tree

My mind went: “Before running the app, I am going to make use of this moment to open the Visual Studio Code at this directory,” so I entered [ code . ] command.

The terminal command used to open the code editor at the root directory
[ code . ] The command used to open the code editor at the root directory

“Ok, let’s run the app,” I thought.  I entered [ npm start ], and off it went.

Git Commands Time!

“Before doing anything to the code, I need to make sure that locally I have the latest version of what is in development,” my thoughts continued.

So it’s time for the: “Git Routine.”

“But first ☝️, let me open a new Mac terminal tab, by typing [ command + t ], to keep the app running on the current one,” I said to myself.

Next, I will detail what consists the Almost Four Steps Git Routine. I am assuming that you know git basics. Do not worry if you do not know!  Here is a quick intro.

Almost Four Steps Git Commands Routine

Check Branch Status

First, check the status of the local work tree. Because frankly, I always forget what I was doing. So, I enter the [ git status ] command.

git status command print
Terminal after entering git status

If the branch is not clean, save changes

Second, I have learned, after many attempts, that git will not change branch if there are code changes, and changes are not stashed (saved temporarily) or committed (merged with master branch eventually).

So I proceeded to enter [ git stash ] to save changes temporarily.

Now let’s see if I can change the branch from the current one to the development branch to make sure that I have the current version of the remote development branch.

git status print with uncommited or unstashed changes
Branch with changes not stashed or committed
git stash command stashed code changes
[ git stash ] – Changes are stashed (saved temporarily)
git status command to check if tree is clean
Checks [ branch status ] to see if the working tree is clean

Change local branch

Now that the branch is clean, I need to change the HEAD of the work tree to the development branch. [ git checkout development ] does that.

git checkout development command to switch HEAD from feature/product to development
[ git checkout development ] switches HEAD working tree to the development branch

Update development branch

Finally, update the local development branch with the remote repository’s development branch. So I enter [ git pull origin development ].

git pull origin development terminal command updates content from remote development branch to local development branch
[ git pull origin development ] command updates content from remote development branch to local development branch

The command [ git pull ] fetches the development branch content on the remote repository and merges the remote branch content with local branch content. The command [ origin development ] refers to the branch that the system will look up to make the update. Origin refers to repository of origin, in this case, the remote repository. Development refers to the name of the work tree branch that the systems looks up to make updates.

After Git Commands Routine

From this point forwards, my git commands vary from what I need to do in the day. This time, I need to fix a bug, so I need to create a new branch and perform those changes on that new branch. That requires me to change my HEAD work tree from development to the newly created work tree branch.

“What will be the name of the new branch?” started my thoughts again.

“Something verbose, straight to the point,” pointed out a thought with the voice of my team lead.

“Let’s go with fix/this-feature” I decided. So I entered [ git checkout -b ‘fix/this-feature’ ].

[ git checkout ] switches branches of work tree, [ -b ] creates a new working tree branch, and [ ‘fix/this-feature’ ] is the new branch name.

Create and switched to a new branch
Create and switched to a new branch

To make sure that I am not in the development branch anymore, I hit again [ git status ].

[ git status ] to confirm that I am working on the new branch
[ git status ] to confirm that I am working on the new branch

“Yeah, I am at the new branch of the work tree,” I confirmed to myself.

Next, I need to merge the updated branch with the new one, so the new work tree branch is up to date with the updated development branch. The command [ git merge development ] does that merge.

Few. I am glad that I got that out of the way. These steps up until changing branches from development to the new o reworked branch always make me nervous.

“Now, I am ready to catch that bug!” And so I turned to my application and code editor to search for it.

An error occurred

I was having a groove on while writing code, and everything was working fine until something happened that a confusing error started appearing.

“Another application is already using the port,” it read.

As a great debugger, I stopped the program with [ control + c ]

terminal output after control + c
Terminal after entering [ control + c ]

…. and reran it. But it did not help.

So I asked my friend Google for some help, and it suggested to locate and kill the port process. To do this, I needed to identify the process id that I intended to kill and, well, terminate it.

The command to locate and display the list of the processes happening on a port is [ lsof -i:PORT ], where [ lsof ] stands for a list of open files, [ -i ] is the list of processes and [ PORT ] is the port number that we want to review. This case is the port 3000 so [ lsof -i:PORT ] is really entered as [ lsof -i:3000 ].

terminal output after running lsof -i:300 command
List of processes running in port 3000

After locating the process that I wanted to terminate, I proceed to enter [ sudo kill -9 15010 ] to kill the process. Where 15010 is the terminated processes’ PID (process identification number).

terminal output after running the command [sudo kill -9 15010
[ sudo kill -9 15010 ] to kill the process with PID 15010 running at port 3000

Ready to start rerunning the app.

“Grrrrrlrllrrlrlr” growled my belly. “I am hungry, and I cannot think with my stomach screaming,” I thought.

“Let’s go to lunch,” suggested Ramona.

“Please!” I responded and headed out to lunch feeling like:

Thanks for reading!

You can get a new post notification directly to your email by signing up at the following link.

The following CTRL-Y articles are related somewhat to this post. You may want to check them out!:

Side Note – Cheat sheets and a playlist fro you

Enjoy a couple of Cheat Sheets including the commands used throughout this story!

Also, I wrote this story with the newly released Four Tet album, Sixteen Oceans playing in the background. The beginning of the first song sets an incredible mood for a subtle yet productive day. It has been my go-to album during this whole self quarantined time.

Leave a Reply

Your email address will not be published. Required fields are marked *