Git Bash — Pull, Commit, and Push

Pete Thomasberger
4 min readApr 1, 2021

In the last article, we left off with a best-practice workflow for working with Version Control Systems that is important enough to mention again.

1. Always remember you are working off a server, potentially, in a team environment with other developers.

2. Always pull the most up-to-date version from the webserver.

3. Commit your changes.

4. Push your commit back to the server.

This will ensure that a proper workflow is implemented with the least chance for error.

Now that we have successfully connected our project to the GitHub web server and have the ability to pull and push versions and changes, let’s do just that. To pull from GitHub, we first need to know where we are pulling from. This is where Branches come in. Branches are essentially different development environments in which we can make our changes. For instance, we have been working within the project’s main branch, indicated by the name (main) as seen below. So, we will want to pull the latest version of the main branch from the webserver, enabling us to have the most up-to-date version of that branch.

To pull from the Main branch on the webserver, we will need to use the command git pull origin main. And to break this command down, we use git because this is a Git command, pull because we are pulling data from the webserver, origin which is the GitHub website, and main which is the name of the branch we are pulling.

After we pull the main branch from the webserver, we can verify which branch is active by using the command git branch. We can see that main is in green with an * in front of the name, indicating that the main branch is the active branch.

Next, we will need to ensure that we are tracking the changes that were made before we can commit anything. We can check the tracking status using the command git status.

Notice, there are several files and folders from our project that are in red, which means they are not being tracked. We can add specific files or folders to the tracked list using the command git add and the file or folder name we would like to add. For example, let’s add the “Assets folder”. The command would be git add Assets/. Then, if we check the status again, we will see that the Assets folder is green, indicating it is now being tracked.

Alternatively, we can use the command git add . if we want to add all of the files and folders to the tracked list.

Now that our files are being tracked, we are ready to implement our first commit and indicate what changes have been made to the pulled branch. For now, we will indicate that we have created a new project. The command for making a commit is git commit -m (-m stands for “message”) and the message is the change(s) made. So, the full command for this example would be git commit -m “Created new project”.

Now that we have successfully made our first commit, we need to push the commit to the webserver using the command git push origin and the name of the branch we are pushing the commit to. For this example, the command will be git push origin main.

We can now go back into GitHub, refresh our repository dashboard page, and we will see that we have a new commit successfully added with the “Created new project” title.

In the next article, we will be creating additional branches, merging them together.

--

--