More Git Commands
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.
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:
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.
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.
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.
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.
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”
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.
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!








