Start using Git version control on the command line

If you want to start using Git version control and GitLab, make sure that you have created and/or signed into an account on GitLab.

Open a shell 

Depending on your operating system, you will need to use a shell of your preference. Here are some suggestions:

Check if Git has already been installed 

Git is usually preinstalled on Mac and Linux.

Type the following command and then press enter:

git --version

You should receive a message that tells you which Git version you have on your computer. If you don’t receive a “Git version” message, it means that you need to download Git.

If Git doesn’t automatically download, there’s an option on the website to download manually. Then follow the steps on the installation window.

After you are finished installing Git, open a new shell and type git --version again to verify that it was correctly installed.

Add your Git username and set your email 

It is important to configure your Git username and email address, since every Git commit will use this information to identify you as the author.

On your shell, type the following command to add your username:

git config --global "YOUR_USERNAME"

Then verify that you have the correct username:

git config --global

To set your email address, type the following command:

git config --global ""

To verify that you entered your email correctly, type:

git config --global

You’ll need to do this only once, since you are using the --global option. It tells Git to always use this information for anything you do on that system. If you want to override this with a different username or email address for specific projects, you can run the command without the --global option when you’re in that project.

Check your information 

To view the information that you entered, along with other global options, type:

git config --global --list

Basic Git commands 

Go to the master branch to pull the latest changes from there 

git checkout master

Download the latest changes in the project 

This is for you to work on an up-to-date copy (it is important to do this every time you start working on a project), while you set up tracking branches. You pull from remote repositories to get all the changes made by users since the last time you cloned or pulled the project. Later, you can push your local commits to the remote repositories.


When you first clone a repository, REMOTE is typically “origin”. This is where the repository came from, and it indicates the SSH or HTTPS URL of the repository on the remote server. NAME-OF-BRANCH is usually “master”, but it may be any existing branch.

View your remote repositories 

To view your remote repositories, type:

git remote -v

Create a branch 

To create a branch, type the following (spaces won’t be recognized in the branch name, so you will need to use a hyphen or underscore):

git checkout -b NAME-OF-BRANCH

Work on an existing branch 

To switch to an existing branch, so you can work on it:

git checkout NAME-OF-BRANCH

View the changes you’ve made 

It’s important to be aware of what’s happening and the status of your changes. When you add, change, or delete files/folders, Git knows about it. To check the status of your changes:

git status

View differences 

To view the differences between your local, unstaged changes and the repository versions that you cloned or pulled, type:

git diff

Add and commit local changes 

You’ll see your local changes in red when you type git status. These changes may be new, modified, or deleted files/folders. Use git add to stage a local file/folder for committing. Then use git commit to commit the staged files:


Add all changes to commit 

To add and commit all local changes in one command:

git add .

Note: The . character typically means all in Git.

Send changes to 

To push all local commits to the remote repository:


For example, to push your local commits to the master branch of the origin remote:

git push origin master

Delete all changes in the Git repository 

To delete all local changes in the repository that have not been added to the staging area, and leave unstaged files/folders, type:

git checkout .

Delete all untracked changes in the Git repository 

git clean -f

Unstage all changes that have been added to the staging area 

To undo the most recent add, but not committed, files/folders:

git reset .

Undo most recent commit 

To undo the most recent commit, type:

git reset HEAD~1

This leaves the files and folders unstaged in your local repository.Warning: A Git commit is mostly irreversible, particularly if you already pushed it to the remote repository. Although you can undo a commit, the best option is to avoid the situation altogether.

Merge created branch with master branch 

You need to be in the created branch.

git checkout NAME-OF-BRANCH
git merge master

Merge master branch with created branch 

You need to be in the master branch.

git checkout master
git merge NAME-OF-BRANCH

Sumber: Gitlab.Com

Currently and mission…

Maaf lama tidak menghantar tutorial! Jadi, apa yang saya sedang lakukan pada waktu ini?

1) Membangunkan Portal eLearning Psikiatri
2) Membangunkan Sistem MealPlan
3) Mengemaskini Portal Aktiviti
4) Mengajar PHP & mySQL : Basic to Intermediate (insyallah)

Dan masih terus menambah ilmu mengenai:

1) Laravel 4.2
2) Sublime Text 3
3) Git 1.9.4
4) PHP 5.5.15 (will upgade to 5.6 later)


GIT – Distributed Version Control and Source Code Management (SCM) System

Introduction To GIT

  1. Abstract
  2. Creating a Repository
  3. Checking Out A Repository
  4. Add And Commit
  5. Pushing Changes
  6. Branches
  7. Update and Merge
  8. Tagging
  9. Revert To Specifit Commit


GIT is a distributed version control and source code management (SCM) system developed by by Linus Torvalds for Linux kernel development, Git has since been adopted as the choice of source code management by many projects and companies. This document covers the creation, usage and management of the GIT versioning system.

The installation of GIT is beyond the scope of this tutorial, however, here are some links that will help


Creating a Repository

To create a repository for your project, select a place where you have write privileges. For our purposes here, we will create a repository for a project name ACL. So lets begin with creating the repository(repo).

mkdir ~/git_repos
mkdir ~/git_repos/acl
cd ~/git_repos/acl
git init

The above commands will firstly create a directory name .git in which, in turn, will contain some directories and files need to work with the GIT system. A quick look inside the .git directory shows us the following

# ls ~/git_repos/acl/.git
branches config description HEAD hooks info objects refs

Checking Out A Repostiory

If you are using a local repository, checking out a copy is as simple as:

git clone ~/git_repos/acl

If you are checking out a remote repository, then use this command.

git clone username@hostname:/home/kevin/git_repos/acl

The local repository consists of three “trees” maintained by git

Working Directory
Contains the acutal files
Acts as a staging area
Points to the last commit

The workflow will look like this.

WORKING DIR -> add -> INDEX -> commit -> HEAD

Add And Commit

When you add a file to GIT, the addition is stored as a proposed changed, which means it is stored in the Index. To add a file named acl.php is as simple as:

git add acl.php

If you had multiple files you wanted to add, you can use the command

git add *

Currently the file is just a proposed addition, and not commited to the repository. To commit we use git commit.

git commit -m “Message to say I added acl.php file”

The acl.php is now in HEAD, but not yet in the remote repository repository. Any additions and changes need to be pushed to the remote repository before they are available to all.

Pushing Changes

To push changes to the remote repository, the git push command is used.

git push origin master

The master can be whatever branch you want to push the changes to.

Thats IT!?. Yup, thats it

If you have not cloned an existing repository and want to connect your repository to a remote server, you need this command

git remote add origin server_name

Now you are able to push your changes to the selected remote server


Branches are used to develop features in isolation. The master branch is the “default” branch when you create a repository. Use other branches for development and merge them back to the master branch upon completion.

The workflow will look like this..

           ---------- Feature ----------
          |                            |
          |                            |
--------------------- Master -------------------------
       branch                        merge

So, to create a branch called my_feature_branch, and switch directly to it

git checkout -b my_feature_branch

You should see a message like

Switched to a new branch ‘my_feature_branch’

Now, to switch back to master brach

git checkout master
Switched to branch ‘master’

A local branch is not available to others, as it is not yet in the repository. The branch needs to be pushed to the remote repository to be available to all.

git push origin my_feature_branch

And finally, to delete the branch, we use the -d switch

git branch -d my_feature_branch
Deleted branch my_feature_branch (was b37035b).

Update and Merge

Of course, you are not the only person using the repository. Others will commit changes and you need to keep your local copy up to date by pulling new changes from the remote repository. To do so, use the pull command. This will both pull and merge changes from the remote repo, into your local copy.

git pull

To merge another branch into your active branch eg: master, use this command.

git merge my_feature_branch

When git pulls from the remote repository, or merges a branch, it tries to auto-merge the content. Inevitably, there are conflicts. You are responsible to merge those conflicts manually by editing the files shown by git. After changing, you need to mark them as merged. Using:

git add

Some of these conflicts can be avoided by checking for conflicts before merging with git diff

git diff source_branch target_branch



Tagging a release is a great idea for tracking releases and milestones in a project. Those who are familiar with SVN would be familiar with this concept. To create a new tag, first use the git log command to get the last commit ID and then use git tag with the ID you just gained.

git log
commit b37035b424c82dd1b4baee3b8184ddbead32edd0
Author: Kevin Waterson <kevin@jyotish.(none)>
Date: Fri Jul 5 09:37:27 2013 +1000git tag 1.0.0 b37035b424c82dd1b4baee3b8184ddbead32edd0

Another simple way to use a an annotated tag in GIT, which is really just a pointer to the current commit is this. This example assumes a tag for a release of version 37 of a project.

git tag -a v37 -m ‘Release 37’

Revert To Specifit Commit

Sometimes you need to revert or rollback to a specific commit. Here we show how to revert back to commit id 296b09c

git reset 296b09c
git reset –soft HEAD@{1}
git commit -m “Revert message to tell you have reverted”
git reset –hard

GIT (Version Control System)

Apabila kita membangunkan sesuatu aplikasi secara berkumpulan, secara tidak langsung akan berlaku perkongsian penggunaan fail. Pada saat ini, kita memerlukan suatu aplikasi yang boleh mengawal versi fail yang kita gunakan sama ada fail konfigurasi, fail teks atau sebagainya. Apabila berlaku perubahan kandungan dalam fail tersebut, maka aplikasi ini akan memudahkan pengguna/kumpulan tadi mengenalpasti perubahan yang berlaku.

Salah satu aplikasi yang sedang meluas digunakan pada masa ini adalah Git.  Walaupun terdapat beberapa protokol lain seperti CVS dan SVN, tetapi GIT lebih popular digunakan kerana kelajuan dan kecekapannya, mudah digunakan serta dapat digunakan dalam berbagai Sistem Operasi (OS).

Git adalah software (open source) yang direka untuk mengendalikan segala-galanya, dari pembangunan projek yang kecil sehingga projek yang sangat besar dengan kelajuan dan kecekapan yang sangat optimum. Git adalah mudah dipelajari dan  mempunyai tiny footprint with lightning fast performance. Antara kelebihan lain yang ada pada Git adalah:

  • support main and local repository
  • tidak memerlukan network connection untuk melakukan git commit
  • branching adalah local dan local repository adalah tanggungjawab programmer itu sendiri

Insyallah pada post yang akan datang PakCu akan tunjukkan pemasangan Git pada OS Windows 7 serta GUI yang boleh dipasang bersama untuk memudahkan pengguna menggunakan GIT.


First of all, PakCu nak ucapkan berbanyak terima kasih kepada Saudara Iszuddin Ismail (Senior Web Developer at Kengkawan IT Solutions) kerana sudi menjemput PakCu utk turut hadir sama bersama-sama beberapa lagi Pakar IT antaranya Akmal Fikri, Mior Muhammad Zaki, Haezal Musa, Muhamad Hanafiah, Nurhanna Aziz, Ashikin Asraf, Izwan Robotys, Azree Hanifiah, Muhammad Hamizi dan Nurul Azrad; pada yg tak sebut nama jangan marah ye… Tak lupa juga kepada Pihak Pengajur Program dan tuan rumah (KPTMKL)

Walaupun program diadakan pada Hari Jumaat tapi pengisiaannya sgt bagus. Bermula dengan topik “Apa yg perlu anda tahu untuk menjadi seorang programmer” oleh Saudara Iszuddin. Kemudiannya disusuli dengan topik “Kehidupan sebagai seorang programmer” oleh Saudara Zaki. Sebelum berehat tengahari utk solat Jumaat, pelajar diberi lagi pengetahuan oleh Saudara Izwan dengan tajuk “MVC – Code Igniter”. Selepas solat Jumaat, program diteruskan dengan pembentangan oleh Saudara Hamizi dengan tajuk “GIT” serta diakhiri dengan tajuk “JQuery” oleh Saudara Nurul Azrad.

Tak sia2 bos PakCu bagi pelepasan untuk menghadiri program ini. Banyak ilmu baru yg memberi manfaat serta tambahan /pemantapan ilmu yang telah ada. Memang PakCu setuju dengan kata2 Saudara Zaki, Programmer has no life!! Tapi kalo kita pandai manage masa, insyallah kita tidak akan jadi hamba kepada kerja. Apa yg PakCu dpt simpulkan pada program tadi:

1. Better use div drp table. Pakai table hanya utk paparkan senarai data sahaja. Kenapa? Sebab apabila kita pakai div, maka kita akan belajar CSS. Kenapa nak pakai CSS? CSS memudahkan kita utk mengawal UI (User Interface) agar mendapatkan feedback yg positif utk UX (User Experience). Selain itu CSS juga memudahkan kita apabila kita hendak menggunakan JQuery

2. Setkan benchmarking/target setting dlm sesuatu tempoh, apa yg akan kita perolehi (ilmu/kepakaran). Contohnya katakan dalam tempoh 2 bulan kita nak mahir dengan Code Igniter. So kita kena berusaha untuk mencapai target kita tu. Kalo selepas tempoh tersebut kita masih tak capai target tadi. Lihat balik kelemahan diri. Adakah kita kena beralih kpd framework yg lain atau programming memang bukan bidang kita 🙂

3. Mula cari framework yg sesuai dengan keperluan anda. Penerangan yg menarik daripada Saudara Izwan tentang MVC dan kelebihan CI telah menarik minat PakCu untuk mencuba Code Igniter (CI) sebagai framework utk projek2 akan datang. Jika sebelum ini PakCu pernah mencuba CakePHP dan PHPHyppo jadi sekarang ini, mula nak mencuba CI pula. CI nampak lebih flexible dan mudah difahami.

4. GIT adalah satu apps yg memudahkan kita untuk mengawal versi sistem kita. Kalo sebelum ini kita terpaksa membuat folder/fail xxxx_latest.php. Kemudiannya xxxx_latest_paling.php tapi kita dengan penggunaan GIT akan lebih memudahkan kita menguruskan fail2 code kita dengan lebih sistematik dan teratur. Terdapat 2 jenis GIT iaitu GIT dan juga GITHUB. Perbezaannya adalah GitHub adalah utk public (dikongsikan dengan org lain melalui portal github iaitu Manakala GIT pula lebih baik digunakan sekiranya kita membangunkan aplikasi secara berkumpulan di organisasi kita.

5. Masanya telah tiba dimana web kini lebih berbentuk dinamik dan interaktif serta mesra pengguna. Jika dulu kita terpaksa refresh/load page apabila kita menghantar sesuatu input melalui form. Tapi dengan adanya JQuery dan Ajax, page tidak lagi perlu direload. Saudara Nurul Azrad telah menunjukkan contoh2 yg menarik dlm pembentangan beliau.

Syabas kepada pihak penganjur dan Penceramah/Fasilitator yg turut hadir bagi menjayakan program ini.