Guide for getting started with git

Git is a distributed revision control and source code management system with an emphasis on speed. Git was initially designed and developed by Linus Torvalds for Linux kernel development. Git is a free software distributed under the terms of the GNU General Public License version 2.

This tutorial explains how to use Git in Ubuntu for project version control in a distributed environment while working on web-based and non web-based applications development.


Create a new repository

create a new directory, open it and perform a git initto create a new git repository.


Checkout a repository

create a working copy of a local repository by running the command
$ git clone /path/to/repository
when using a remote server, your command will be
$ git clone username@host:/path/to/repository

or
$ git clone https://github.com/codeleaf/crm

Where ‘codeleaf/crm’ is the REPO link. Which will ask for your git username and password.


Workflow

your local repository consists of three “trees” maintained by git. the first one is your Working Directory which holds the actual files. the second one is the Index which acts as a staging area and finally the HEAD which points to the last commit you’ve made.

trees


Add & Commit

You can propose changes (add it to the Index) using

$ git add

For Multiple Files

$ git add *

This is the first step in the basic git workflow. To actually commit these changes use

$ git commit -m “Commit message”

Now the file is committed to the HEAD, but not in your remote repository yet.


Pushing changes

Your changes are now in the HEAD of your local working copy. To send those changes to your remote repository, execute

$ git push origin master

Change master to whatever branch you want to push your changes to.

If you have not cloned an existing repository and want to connect your repository to a remote server, you need to add it with

$ git remote add origin

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


Branching

Branches are used to develop features isolated from each other. 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.

branches

Leave a comment