Sitemap

More Git Commands

4 min readJan 22, 2024

--

In trying to understand some Git terminology, I compared the terms with things I do in baking. Before we begin, we want to ensure we have the correct recipe and all ingredients on hand. We will check our cookbook or recipe collection, and our shelves for necessary ingredients.

Get Stephanie Wells’s stories in your inbox

Join Medium for free to get updates from this writer.

In Git, we’ll check our remote repository for files, and overall status with the commands git pull and git status, which I talked about in my last article here. Now, we’re further along in our baking scenario. We want to try a variation of our recipe while keeping the original intact. In baking, we might start a different recipe card. In Git, we’ll use the branch command.

Press enter or click to view image in full size

Git branch allows us to work on different versions of our code simultaneously. Let’s take a look at this concept from a non-technical perspective. Say we have a basic cookie recipe. It could start with the usual ingredients of flour, butter, sugar and eggs. This recipe (our code) would reside in the main branch. Now, we want to test this base recipe with some additions, such as cashews and dried fruit, and maybe a change in the type of flour. We still want to preserve our main recipe, so we’ll create a branch, let’s call it “dev”. So we’ll type git branch dev:

a screenshot of the git console displaying the command git branch dev

Git will create the branch. We can check out our branches by typing git branch. We’ll see a list of branches including our current “main” branch, plus the newly created branch. There will be an asterisk beside the branch we are currently in. In this case, we are still in the main branch.

a screenshot of the git console displaying the command git branch with the results dev and main below. The branch main has an asterisk before it, denoting which branch we are currently in.

We can navigate to the new branch with the “switch” command. We do this by typing git switch dev. We can verify that we’re now in the dev branch by typing git branch again and looking for the asterisk.

a screenshot of the git console displaying the command git switch dev, and the confirmation message “switched to branch dev” Additionally, it shows the command git branch, with the corresponding results and the asterisk now beside the dev branch showing that we are now working within that particular branch.

We can, of course add more branches and work on more features and even merge those features into our main once they’ve tested to our liking in a different branch. Once we have branches set up, we can modify as we see fit. Let’s say we’ve been working on our biscuit recipe in our main branch. We’ve made some local changes that we want to put into production in our bakery. This is where we’ll use our git pull and git status commands that I discussed earlier here to see the difference between our local git and remote repository.

a screenshot of the git console showing the git status command and a list of untracked files that have not been added to the repository. The new files are in red.

We’ll first add those files listed in red so they can be marked for upload or committed to the repository. We can add each file one at a time by typing git add Assets, or, to save time, we can simply type git add . to add everything.

Press enter or click to view image in full size
a screenshot of the git console showing the git add . command and the string of warning messages that these will introduce changes to the repository.

There will be a ton of warning messages to tell us that our remote files will be replaced with the new files we’ve queued for adding. As long as there are no error messages, we can continue to the commit. We commit these changes by typing git commit. It’s advisable to add a message of some sort to help track what these changes are. We do that with -m. So, our statement in this case looks like git commit -m “Created New Unity Project”

a screenshot of the git console showing the git commit -m “Created New Unity Project” command and the string of confirmation messages.

Now that the changes have been committed for uploading and saving, we can do that with git push. This command will take our changes and upload them to the repository so that everyone can use them.

a screenshot of the git console showing the command git push origin main and the resulting progress and confirmation.

You’ll notice that the syntax for git push looks similar to git pull. The parts work the same, with exception that we’re now sending files instead of receiving them to view.

Now we’ve covered some more basic Git commands to get us going. We always have the option of typing git — help to see more commands and how to use them. Enjoy branching and creating!

--

--