It is necessary to learn some basic Git commands to make this work
Git Commands
The basic commands needed for version control
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.
- Pull from the server
- Add and Commit
- 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:
This displays a list of the git commands:
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.
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.
- 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
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:
Yes, that is a period after the add. It just means add all files.
Now, if we issue a git status command all files should be in green. this means they have been added to the commit.
3. Make the actual commit
The following git command actually creates the commit:
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.
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:
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.
In my next article, I will be writing about Branching. This is a very important topic as you will see.