Getting Started with Git

What is Git and GitHub?

Git is a repository version source control system that keeps track of files (of any format) and folder changes that are physically kept on the computer hard drive file (e.g. C drive) or shared network drive structure on Windows or Mac OS.

Meanwhile,  GitHub is an online repository source control on the cloud where it host  unlimited public repository  to individual registered users who sign up fora GitHub account. Once users have a GitHub account, they can begin to upload and publish open source code projects and solutions that are shared to the community.

GitHub also host private repository for individual or as an organization at a monthly price that users have to pay if interested.  Thus GitHub does NOT offer any free online private repository, except for Visual Studio Online that offers private repository for up to the first 5 users.

The starting pricing model (at the time this blog was published) for an organization to host private repository is:

  • $9 / month for the first 5 users hosted at GitHub; or
  • From $21/month for a pack of 10 users hosted on SMS private cloud like Windows Azure.

To get started using Git, follow the steps below:

  1. Download and install Git from this site for either Windows or Mac OS. Accept the default settings in the installation wizard dialog box
  2. Download and read eBook Pro Git by Scott Chacon and Ben Straub that is available to read online for free.
  3. Create a new folder on the desktop hard drive
  4. Right mouse click on the folder and “Git Bash Here”. This will open an Git command prompt window starting on the folder that you have just created in step 3
  5. Create a Git repository under the current working area folder. This is done by going into Git command prompt window,  type: get init
  6. Step 5 will create an invisible “.git” folder inside the current working folder. To display a list of files and folder under current working area, type cmdlet: ls -la

How to add a  file/folder into Git?

The process of adding a file into Git is to add it to a staging area. Then commit (check in) the file in staging area

  1. To add a file to staging areal,  type: git add <file name/folder name> This cmdlet will add individual file or add bulk of files (inside the folder) into the staging area.
  2. Type: git status   This will get the status list of all  files under the working folder area. The status messages are:
  • New files – Recently new files added to staging environment (green font)
  • Untrack files – Files that are not yet committed to Get repository (red font)
  • Changes to be committed – Files that has been added into the staging environment but not yet committed (yellow/orange font)

3. Now you are ready to commit (check-in) the file into Git repository, by typing: git commit -m “revision 1”

4. To verify that the comments was stamp onto the committed files, Type: git log


Other Git cmdlets:

  • Git add .  = Add all the list of untrack files to be ready for commitment in the staging environment area.
  • Git commit -m “add comments here” = Commit all the files in staging. Parameter -n means to add the comments and display message during commit process.
  • Git config -global user.email daveliong@yahoo.com.au = Add your profile into the committed files
  • Git config -global user.name “David Liong”
  • Git log = Display the last commit process transactions
  • Git checkout <file name> = Undo pending changes made to a file in the current working area $. All save changes made to a file in the current working area will be lost and will be reverted back to the last committed changes in version history
  • Git checkout –<file name> =  Discard files that were deleted in working directory folder. Typically undo deleted file to restore file back from last committed change in  version history. Alternatively use: git checkout <file name> command
  • Get reset HEAD <file name> = Unstage from commit, meaning remove files out of staging environment back and revert file to current working.

Recommended Links

The next step is learn how to get started using GitHub

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s