It is necessary to learn some basic Git commands to make this work

Git Commands

The basic commands needed for version control

Marc Frappier

--

Creating The Initial Commit

When you are working on a project in collaboration with others, it is essential to follow the following three steps in this order.

  1. Pull from the server
  2. Add and Commit
  3. Push to the server

This will prevent you from accidentally overwriting someone else’s updates if you don’t have them included in your own version first.

If you ever need a reminder on git commands, you can always type this at the command prompt:

git help command

This displays a list of the git commands:

Displaying git help

1. Pulling from the remote server

With this next command, git pull origin master will pull changes from the origin remote, master branch and merge them to the local checked-out branch.

pulling from the repository master branch

What this means is that it will go to the repository (remote) to the master branch and pull or download a copy of what is there and merge it with what we have on our local machine updating it.

You won’t loose you work, you are just adding anything others might have done before you push or upload to the repository.

2. Making the first commit

There are several steps to make the commit.

  1. We must first check to see if there are any changes made to our local file system that need to be committed. To do this we issue the command
git status command
demo of git status

As we can see, there are three folders that need to be committed. We can tell because they are in red. So the next step is as follows:

2. Add the files to the commit

In order to do this, we can add individual files or folder to the commit by issuing a git add <filename> command. But normally you want to add all files and folders on the list to the commit. To do this we issue the following command:

adding all files to a commit

Yes, that is a period after the add. It just means add all files.

adding files to a commit

Now, if we issue a git status command all files should be in green. this means they have been added to the commit.

Files added to commit

3. Make the actual commit

The following git command actually creates the commit:

git commit command

Although the -m “some comment here” is optional, is is recommended it be done. What this does is it adds the comment to the commit once we push it to the server. This way we can tell which commit it actually is. For example, if we type

we would know exactly which commit it was we were looking at.

Updated repository after pushing a commit

3. Pushing Files to the Server

Now that we pulled the latest version from the remote server, added and committed our modifications with a comment, we are ready to push them to the remote server to update it.

The following command does this:

pushing committed files to server

Once it is done, it will prompt us that everything is up to date.

If you check the repository on GitHub, refresh the page if you are in the repo already, you will se the changes added.

Changes made to repository on GitHub

In my next article, I will be writing about Branching. This is a very important topic as you will see.

--

--

Marc Frappier

Poultry Scientist by profession, Computer Scientist at heart. After many years in the poultry business, I have decided to give my passion for technology a shot.