Tuesday 19 April 2016

Version Controller : Git - commands

·         git config
Sets configuration values for your user name, email, gpg key, preferred diff algorithm, file formats and more. Example: git config --global user.name "My Name" git config --global user.email "user@domain.com" cat ~/.gitconfig [user] name = My Name email = user@domain.com
·         git init
Initializes a git repository – creates the initial ‘.git’ directory in a new or in an existing project. Example: cd /home/user/my_new_git_folder/ git init
·         git clone
Makes a Git repository copy from a remote source. Also adds the original location as a remote so you can fetch from it again and push to it if you have permissions. Example: git clone git@github.com:user/test.git
·         git add
Adds files changes in your working directory to your index. Example: git add .
·         git rm
Removes files from your index and your working directory so they will not be tracked. Example: git rm filename
·         git commit
Takes all of the changes written in the index, creates a new commit object pointing to it and sets the branch to point to that new commit. Examples: git commit -m ‘committing added changes’ git commit -a -m ‘committing all changes, equals to git add and git commit’
·         git status
Shows you the status of files in the index versus the working directory. It will list out files that are untracked (only in your working directory), modified (tracked but not yet updated in your index), and staged (added to your index and ready for committing). Example: git status # On branch master # # Initial commit # # Untracked files: # (use "git add <file>..." to include in what will be committed) # # README nothing added to commit but untracked files present (use "git add" to track)
·         git branch
Lists existing branches, including remote branches if ‘-a’ is provided. Creates a new branch if a branch name is provided. Example: git branch -a * master remotes/origin/master
·         git checkout
Checks out a different branch – switches branches by updating the index, working tree, and HEAD to reflect the chosen branch. Example: git checkout newbranch
·         git merge
Merges one or more branches into your current branch and automatically creates a new commit if there are no conflicts. Example: git merge newbranchversion
·         git reset
Resets your index and working directory to the state of your last commit. Example: git reset --hard HEAD
·         git stash
Temporarily saves changes that you don’t want to commit immediately. You can apply the changes later. Example: git stash Saved working directory and index state "WIP on master: 84f241e first commit" HEAD is now at 84f241e first commit (To restore them type "git stash apply")
·         git tag
Tags a specific commit with a simple, human readable handle that never moves. Example: git tag -a v1.0 -m 'this is version 1.0 tag'
·         git fetch
Fetches all the objects from the remote repository that are not present in the local one. Example: git fetch origin
·         git pull
Fetches the files from the remote repository and merges it with your local one. This command is equal to the git fetch and the git merge sequence. Example: git pull origin
·         git push
Pushes all the modified local objects to the remote repository and advances its branches. Example: git push origin master
·         git remote
Shows all the remote versions of your repository. Example: git remote origin
·         git log
Shows a listing of commits on a branch including the corresponding details. Example: git log commit 84f241e8a0d768fb37ff7ad40e294b61a99a0abe Author: User <user@domain.com> Date: Mon May 3 09:24:05 2010 +0300 first commit
·         git show
Shows information about a git object. Example: git show commit 84f241e8a0d768fb37ff7ad40e294b61a99a0abe Author: User <user@domain.com> Date: Mon May 3 09:24:05 2010 +0300 first commit diff --git a/README b/README new file mode 100644 index 0000000..e69de29
·         git diff
Generates patch files or statistics of differences between paths or files in your git repository, or your index or your working directory. Example: git diff


Version Controller : Git - Basic Git commands

Open Git Bash.

git config --global user.name "Your Name"
git config --global user.email name@yourdomain.com
This step is important since the above details will appear when you commit modifications in the repository. In this way your collaborators will know who has updated the repository content.

Initialize a new GIT repository:
user@user:/GIT/test# git init

An empty Git repository is initialized: /GIT/test/.git
Create a file in the working folder:
user@user:/GIT/test# touch README
You can check the status of files in the index versus the working directory:
user@user:/GIT/test# git status
# On branch master # # Initial commit # # Untracked files: # (use "git add <file>..." to include in what will be committed) # # README nothing added to commit but untracked files present (use "git add" to track)
Next, add the newly created file to the index:
user@user:/GIT/test# git add README
Once again check the status of the files in the index versus the working directory:
user@user:/GIT/test# git status # On branch master # # Initial commit # # Changes to be committed: # (use "git rm --cached <file>..." to unstage) # # new file:
README Proceed with the first commit:
user@user:/GIT/test# git commit -m 'first commit' [master (root-commit)

84f241e] first commit 0 files changed, 0 insertions(+), 0 deletions(-)

create mode 100644 README
Check the status after the commit operation:
user@user:/GIT/test# git status # On branch master nothing to commit (working directory clean)
Add the remote repository to your existing local one:
user@user:/GIT/test# git remote add origin git@github.com:user/test.git
Push the modification to the remote repository:
user@user:/GIT/test# git push origin master Counting objects: 3, done.

Writing objects: 100% (3/3), 207 bytes, done. Total 3 (delta 0),

reused 0 (delta 0) To git@github.com:user/test.git * [new branch] master -> master

You can log in your GitHub account and check the newly pushed file:



Version controller : GIT Setup.

Installing and configuring GIT

Download Git software:
Select the suitable binary file and install it. (Installation is pretty straight forward, by clicking Next Next )
You can see these three tools installed. Git Bash, Git CMD, Git GUI.
These three software are meant for same goal.

Create a Git Account:
Signup an account.

Now, We need to say Git hub that my laptop is valid to make a connection.
For this, we need to generate a SSH key in local and add the same in GitHub.

Generate ssh Key:
Open Git Bash.
Paste the text below,
substituting in your GitHub email address.
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
# Creates a new ssh key, using the provided email as a label
Generating public/private rsa key pair.
When you're prompted to "Enter a file in which to save the key," press Enter. This accepts the default file location.
Enter a file in which to save the key (/Users/you/.ssh/id_rsa): [Press enter]
At the prompt, type a secure passphrase. For more information, see "Working with SSH key passphrases".
Enter passphrase (empty for no passphrase): [Type a passphrase]
Enter same passphrase again: [Type passphrase again]
Here is the ssh key generates:  C:\Users\User_Account\.ssh        ( Replace User_Account with system login id)
File Name :  id_rsa.pub

Click on SSH and GPG keys link on the left hand side
Click on ‘new SSH key’ button and then copy FULL content of id_rsa.pub file and paste in the ‘key’ text and click on ‘Ass ssh key’ button.
With this, our laoptop is validated to perform pull, push operations from our github account.














Version controller : What is GIT ?



Git is a source code management (SCM) system. 
GIT alternatives: CVS, Subversion, Perforce, Bazaar, and so on.
GIT Advantages:
Distributed 
Free & Open Source
Fast and Efficient
Unlike other version control systems, Git stores snapshots of file system, but not Differences.

Other Version controls: Maintains only Delta between two modifications.



Git : Every time you commit, it basically takes a picture of what all your files look like at that moment and stores a reference to that snapshot. To be efficient, if files have not changed, Git doesn’t store the file again, just a link to the previous identical file it has already stored.



Git Maintains Local Data base:
To browse the history of the project, Git doesn’t need to go out to the server to get the history and display it for you – it simply reads it directly from your local database

The Git directory (.git folder ) is where Git stores the metadata and object database for your project. This is the most important part of Git, and it is what is copied when you clone a repository from another computer.

 Below is the pictorial representation of Git system.





One more Image to demonstrate Git vs other Systems.