What is version control system?
• Easily management collaboration on a project
• Ability to have an unlimited number of developers working on the same code base
• Easily revert back your files if something happened
Types of Version control:
Centralized: These version control systems are based on the idea that there is a single “central” copy of your project somewhere (probably on a server), and programmers will “commit” their changes to this central copy.
Distributed: These systems do not necessarily rely on a central server to store all the versions of a project’s files. Instead, every developer “clones” a copy of a repository and has the full history of the project on their own hard drive. Hence the copy (or “clone”) has all of the metadata of the original.
Advantages Of Distributed Over Centralized Version Control:Advantages Over Centralized Version Control
1.Performing actions (except pushing and pulling) is extremely fast because the tool access the hard drive, not a remote server.
2,Everything except pushing and pulling can be done without an internet connection.
3.Once you have a group of change sets ready, you can push all of them at once.
4.Since each programmer has a full copy of the project repository,they can discuss the changes before deploying.
What is Git version control ?
Git is a system for tracking changes in source code during software development .
What is GitHub?
It can also be treated as a social platform to share knowledge and work. It also provides access control and several collaboration features,
While Git is a command line tool, GitHub provides a web-based graphical interface
A real life Example of how git works:
For example Carol is at city X and her mom is at city Y which is not nearby .
Carol’s mom wants to cook a dish and wants Carols’s help in it. They want to collaborate with each other in cooking this dish (building software)!
There are three utensils in this story — one master pan, where the actual food is being prepared, two ‘local’ pans; one for Jane and another for her mom, for them to experiment. They add stuff, balance ingredients, etc. in the ‘develop’ pan. In git terms, these are branches within a repository.
Once they find a mix that tastes good in the ‘local’ pan, they merge it with the ‘master’ pan !. And that’s how they commit each of their contributions towards the dish.
Who introduced it ?
Linus Torvalds One of he greatest programmer of the world who created Linux kernel introduced git.
“I name all my projects after myself. First Linux, now git.” Linus Torvalds
Downloading Git :
Git Download link visit
Getting started:
usage: git [OPTIONS] COMMAND [ARGS]
Step 1
Open Gitbash
Step 2
Introduce yourself to git:
git config –global user.name “your name”
git config –global user.email “your email”
Step 3
Change directory by using command or by using Gitbash here to whichever directory you want
Two Scenarios :
Scenario 1: single developer + local repository.
Scenario 2: multiple developers + remote central repository.
Lets go with the first scenario with simple commands:
git init
It creates an empty git repository. Creates the git directory: .git/
We have three stages :
So what is staging Area ?
General meaning of staging area according to Wkipedia “A staging area is a location where organisms, people, vehicles, equipment or material are assembled before use”
git add < filename >
git commit [-m “Commit message.”]
Records changes from the staging area to master.
git commit file1 file2
Records all changes of file1, file2 from working dir and staging area to master.
Examples:
$ git commit README -m “Added README.”
[master dbb4929] Added README. 1 files changed, 1 insertions(+), …
$ git log
commit dbb49293790b84f0bdcd74fd9fa5cab0…
Author:’ your name’ ‘your mail id’
Date: Wed May 15 00:08:46 2010 +0200
More commands
git diff
Shows what changes between working directory and staging area (index).
git log
Shows details of the commits.
git checkout
Get rid of what changed in (between working dir and staging area).
whenever you want to remove, move or rename a tracked file use git:
git rm filename
git mv oldname filename
Scenario 2: multiple developers + remote central repository
The below picture shows the how local repository is interfaced with the Remote repository
Below picture shows in and out of git workflow
Clone a repository in git version control:
git clone < URL >
Creates local copies of the whole remote repository.
Example: git clone https://github.com/abc/xyz.git
Merge a repository in git version control:
git merge
Joins development histories together.( It has to be fetched before to merge)
Push a repository in git version control:
git push
Updates remote masters (both Local and Remote). Requires fetch+merge first