Sunday, 28 August 2016

Learn git basics

GIT is a version controlled system which you can use to maintain code for your project. Its allows a team of people to work together, all using the same files. And it helps the team cope with the confusion that tends to happen when multiple people are editing the same files.It is a distributed source control system its simpler, faster, and easier to use than traditional "centralized" source control systems.

The Benefits of Using git for your local machine :

  • Working offline with the git.
  • Fast to Work With git : Most of the Git operations are fast, mainly because they are performed on your local repository copy.
  • Repositories Are Smaller.
  • Moving or Adding files : Also if you want to add only certain files with some extension with Git you can use wildcards. For example to add only .html files you can run.

git add '*.html'

Ignore Certain Files ex .gitignore
  • Branches for new work developement : Sometimes you need to work on new experimental features without interfering with the main code of your project.
  • Check the Status of Your Changes. (file change are shown in git status modified)
  • Stash Branches : If you are working on a branch of your project but you do not want to commit the changes, you can save the current status of that branch to return to it in the future. You can switch your work to another branch and insert the stashed modification in it. 
  • Cherry Pick Changes from Branches: Git allows to pick one commit from some branch and apply it into the current branch. This operation is helpful for testing purposes. Imagine you want to test some temporary modification or pick some commits done in other branches.
  • Debugging with Git find version : If you have an issue in your code and you want to know when it was introduced and what it is, with the git bisect command you could go back to every commit till you will find the bad one one which the issue was introduced.
1. Installation of git in ubuntu.

Linux – Simply open up a new terminal and install git via your distribution’s package manager. For Ubuntu the command is: 

sudo apt-get install git

 For window machine we recommend git for windows as it offers both a GUI client and a BASH comand line emulator.

After installing git configure the name and email .

git config --global "My Name"
git config --global

2. Creating a new repository.

git stores its files and history directly as a folder in your project. To set up a new repository we need to run the git init command in terminal.It

will enable the git in your local machine.

git init

Create a folder on your Desktop called git_example, open a new terminal and enter the following:

cd Desktop/git_example/
git init

The command line should respond with something along the lines of:
Initialized empty Git repository in /home/user/Desktop/git_example/.git/

This means that our repo has been successfully created but is still empty. Now create a simple text file called index.html and save it in the git_example folder.

3. Checking the file modified status using.

git status

It shows you is everything up to date, what’s new, what’s changed. Now it will show you index.html is new created file.

4. Staging : Git has the concept of a “staging area”. You can think of this like a blank canvas, which holds the changes which you would like to commit.git add command, and finally commit everything (create a snapshot) with git commit.

In our case we have only one file so let’s add that:

git add index.html

If we want to add everything in the directory, we can use:

git add -A

5. Commiting – A commit represents the state of our repository at a given point in time. It’s like a snapshot, which we can go back to and see how thing were when we took it.

git commit -m "Initial commit for index.html"

The -m "Initial commit for index.html" part is a custom user-written description that summarizes the changes done in that commit.

Featured post

How to create dynamic schema in mongodb

Sometime what we need in our application is to create mongodb schema for collection and some of our collection schema are same but names are...

Popular Posts