Git essentials: Get started with Git version control

Learn how Git manages versions and how to install the necessary software to access Git servers where your software project will be stored

1 2 Page 2
Page 2 of 2
  • You have installed the git or git-all software package on your system.
  • You have created an account on a Git hosting service.

The first thing you want to do is perform some basic setup. Whenever you perform a commit operation, your name and email address will be included in the metadata. To set this information, execute the following commands:

ocs@ubuntu:~$ git config --global "Bo Rothwell"
ocs@ubuntu:~$ git config --global ""

Obviously you will replace "Bo Rothwell" with your name and "" with your email address. The next step is to clone your project from the Git hosting service. Note that before cloning, only one file is in the user's home directory:

ocs@ubuntu:~$ ls

The following cloned a project named ocs:

ocs@ubuntu:~$ git clone
Cloning into 'ocs'...
Username for '': borothwell
Password for '':
remote: Counting objects: 3, done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
Checking connectivity... done.

After successful execution, notice a new directory in the user’s home directory:

ocs@ubuntu:~$ ls  ocs

If you switch to the new directory, you can see what was cloned from the repository (only one file so far exists in the repository):

ocs@ubuntu:~$ cd ocs
ocs@ubuntu:~/ocs$ ls

Next, create a new file in the repository directory. You can either create one from scratch or copy a file from another location:

ocs@ubuntu:~/ocs$ cp ../

Remember, anything placed in this directory is not version controlled because this is the working directory. To put it in the local repository, you first have to add it to the staging area and then you need to commit it to the repository:

ocs@ubuntu:~/ocs$ git add
ocs@ubuntu:~/ocs$ git commit -m "added"
[master 3b36054] added
1 file changed, 5 insertions(+)
create mode 100644

The git add command places the file in the staging area. The git commit command takes all the new files in the staging area and commits them to the local repository. You use the -m option to add a message; in this case the reason for the commit was given.

It is important to highlight that no changes have been made to the repository on the server. The git commit command only updates the local repository. You can see that the server repository has not been modified by looking at Figure 7, which shows a screenshot of the web-based interface of the current project. Notice that the original file,, was pushed to the server several days ago, but the new file,, does not have an entry.

git-essentials ch12fig07 Pearson

Figure 7. Server repository is unchanged after executing the git commit command.

Most likely you would make additional changes to your local project and then check in (push) the changes to the server’s repository:

ocs@ubuntu:~/ocs$ git push -u origin master
Username for '': borothwell
Password for '':
Counting objects: 4, done.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 370 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
   12424f5..3b36054 master -> master
Branch master set up to track remote branch master from origin.

See Figure 8 to verify the push was successful.

git-essentials ch12fig08 Pearson

Figure 8. Server repository is changed after executing the git push command.

At this point, all changes of the files from the staging area have been updated to the local repository and the central server repository.

This story, "Git essentials: Get started with Git version control" was originally published by InfoWorld.

1 2 Page 2
Page 2 of 2