Saturday 19 December 2015

Version Control - 04.GitHub_Pull&Fork

GitHub Pull & Fork

Git Pull Request


When ever we forked another users repository and if we want to collaborate with them we can generate a pull request. After forking and cloning to our local computer if we do changes or some new codes have been added to the repository locally the same will be taking effect to the main repository as well. If we need these changes to made permanent to that repository as well then we need to generate a Pull request. Which will be notified to the owner of the main repository. After reviewing that person can accept or reject that request. If that request has been accepted then our changes will be merged to the main repository and committed.

To do this we need to login to our git account in the WebUI after that click on the "Pull Request" button and there after click on "Create Pull Request" button enter some info regarding the pull and click on "Send Pull Request" button.


Updating your Fork


It is also important to know why should we update our forks. Because so many users might be collaborating to the repository you are working and making changes on. In such case you might not know what the changes that have done by the other users. So if we have enabled upstream then every user can know what the other users have done to that repository. As enabling upstream will upload the changes made on their forks will let the other users know the changes.

Adding remote for upstream

# git remote add upstream <PATH_TO_REPO>
# git remote add upstream https://github.com/vmsnivas/bss.git

Fetch the Changes

# git fetch upstream

Merge them into master

# git merge upstream/master master 

Push the changes

# git push origin master

Friday 18 December 2015

Version Control - 03.GitHub_Forks

Git Forks


We might be seeing lots of repositories on github from other users. Most
of the users will secure their repositories. In that case we can't add -
or modify code in their repositories. In such cases we need to fork the-
ir repositories and can make changes. On forking someone's repositories 
we will have a copy of their repositories into our account.

How to Fork?
We need to login to the GitHub WebUI and go to a specific repos-
itory of a person that you want. In the right most area you can a Fork 
button. On clicking on that button you can get a copy of that repository
into your account.

After forking that repository you can clone that repository locally fro-
m your account and you can modify those codes as you need.

Ex : We have 2 users namely USER1 and USER2. User2 want some code from 
User1's repository. First User2 need to go to the WebUI and after to th-
e repository needed. 

https://github.com/user1/repository

Click on the fork button. Once the fork completes then he can have that
repository in his account.

https://github.com/user2/repository

Now he can clone to his local system.

# git clone https://github.com/user2/repository.git

Here we need to know one thing that user2 can even clone user1's reposi-
tory but he can't push the changes until he is permitted to do so.

Tuesday 15 December 2015

Version Control - 02.GitHub_Configs

Configuring your GitHub


Before working with GitHub we need to know that we can make the changes at 3 different levels.
 1. Local
While making the changes locally those changes will take effect to the local user or for a single repo
by which we configured git.
 2. System
If we make any changes at a system level then those changes will take effect to all the users
on that system.
 3. Global
If we make any changes at a global level then those changes will take effect to the repository
globally. In the sense those will be effected to the repository in our global account at Git.

USAGE
git config [<file-option>] [type] [-z|--null] name [value [value_regex]]
git config [<file-option>] [type] --add name value
git config [<file-option>] [type] --replace-all name value [value_regex]
git config [<file-option>] [type] [-z|--null] --get name [value_regex]
git config [<file-option>] [type] [-z|--null] --get-all name [value_regex]
git config [<file-option>] [type] [-z|--null] [--name-only] --get-regexp name_regex [value_regex]
git config [<file-option>] [type] [-z|--null] --get-urlmatch name URL
git config [<file-option>] --unset name [value_regex]
git config [<file-option>] --unset-all name [value_regex]
git config [<file-option>] --rename-section old_name new_name
git config [<file-option>] --remove-section name
git config [<file-option>] [-z|--null] [--name-only] -l | --list
git config [<file-option>] --get-color name [default]
git config [<file-option>] --get-colorbool name [stdout-is-tty]
git config [<file-option>] -e | --edit

We will have several configs like configuring the username, user email address, our terminal appearence
settings and configuring some alias to the commands we wish. These changes will be stored in the .git/config
file. We can do the same thing by editing this file too.

1. Configuring a user name
It is important to configure a username as if we do any commit then everyone using that repository
can know that who made the changes. If we don't the changes will be committed as the user we locally
login with.

# git config --global user.name "<FULL NAME>"
Ex : # git config --global user.name "Arjun Shrinivas"

2. Configuring user's email address

# git config --global user.email emailid@domain.com
# git config --global user.email vmsnivas@gmail.com

3. Configure your default editor for Git
This is the default editor used to edit our git configs.

# git config --global core.editor "/bin/vi"

After doing this try to use the below command to edit your git config. Now you will be able to use
vi editor to edit your git config. In this way you can use any editor. All you need to do is you
should specify the complete path of the editor. You can get it by using like "which vi"

# git config --global --edit

4. Configure alias commands
We can also configure some aliases to use them instead of running some long commands.

# git config --global alias.s "status s" --> Shows the status in silent mode
# git config --global alias.lg "log --oneline --decorate --all --graph"

5. Colorizing display for all users of the system

# git config --global color.ui true

6. Configure Carriage return / Line feed (crlf)
If it is true then it will adds the CRs back in when you check files out to the working directory,
making them easier to edit in some Windows apps which require CRs.

# git config --global core.autocrlf true
7. Configure Push Default
Matching - Pushes all matching branches up to GitHub
Simple - Just pushes current branch up to GitHub

# git config --global push.default simple

8. Configure Pull Default

# git config --global pull.rebase true

9. Configure Reuse Recorded Resolution (ReReRe)
This will records all fixes to merge conflicts and reuses them automatically if the same conflict recurs.

# git config --global rerere.enabled true

10. Configure Git URL

# git remote add -t <BRANCH> -f origin https://<username>@github.com/<username>/<repository>.git
# git remote add -t master -f origin https://vmsnivas@github.com/vmsnivas/bss.git

11. List you Git configs

# git config --global --list

Friday 11 December 2015

Provisioning - 01.Vagrant_Intro

Vagrant for Provisioning


Vagrant is a provisioning tool. If we are about to use Vagrant for provisioning then we need to have one of the provider.
Provider is nothing but a Cloud or Hypervisor environment. We have several providers.
 1. Virtual Box (Most popular to use with Vagrant)
 2. VMware
 3. Open Stack
 4. Docker
 5. AWS

To start using Vagrant you need to download vagrant. Go to the following link and download Vagrant respective to your OS
and its architecture. In my case i am using RHEL6 32-bit, Ubuntu 14.04. So i have downloaded for those

FOR RHEL6 Visit below links and download the packages

https://www.vagrantup.com/downloads.html

Also download VirtualBox with respective to your OS from the below link.
https://www.virtualbox.org/wiki/Linux_Downloads

Now let us install these both.

# cd ~/Downloads
# rpm -ivh vagrant_1.7.4_i686.rpm 
# rpm -ivh VirtualBox-5.0-5.0.10_104061_el6-1.i686.rpm

FOR UBUNTU 14.04 try the following

# apt-get update
# apt-get install vagrant
# apt-get install virtualbox

I am preferring RHEL or CentOS in my case as I have been facing some issues working with Vagrant in Ubuntu.
I'll be updating soon on complete procedure working with Ubuntu as well.

Now let us come to the case of RHEL.
While installing VirtualBox if you found any dependency failure for libSDL feel free to install that through YUM.
And try installing VirtualBox then. You will also need to install the kernel modules which are required for VirtualBox.
Please install the following packages, after that VirtualBox package and reboot your machine.

# yum install kernel* dkms gcc libSDL*

Once you are done then create a directory for Vagrant as your Vagrant workspace.

# mkdir /vagrantProject
# cd /vagrantProject

Now initialize your first VM using vagrant.
In this case i am using Ubuntu to be installed through Vagrant.

# vagrant init ubuntu/trusty64

You are ready with your first setup config which is stored in the Vagrantfile in your Vagrant Project directory.
Start your VM with "vagrant up". It will first download the ubuntu image from virtualbox and once the download finishes
it will start it up.

# vagrant up

Now you can ssh to your ubuntu box by using "vagrant ssh"

# vagrant ssh

If you want to shutdown your VM you can use
# vagrant suspend
(or)
# vagrant halt

If in case you don't need that VM then you can destroy that VM.
# vagrant destroy

Tuesday 8 December 2015

Version Control - 01.GitHub_Intro

GitHub Intro


Step 1
Login to github.com and signup for a free account.
If you need a private repository then you need to signup for paid account.

Step 2
Login to your Linux machine and create a direcotry for git
# mkdir /git

Step 3
Configure your username and email. So that if someone did any commit then everyone will know who have made it.
# git config --global user.name "User Name"
# git config --global user.email <email_id>

Step 4
Go to that directory and create a new directory for your repository if you
have multiple branches within the repository in your git account.
Else you can add your repository directly.
Case 1: Repository with default branch or a single branch.
Go to your git directory
# cd /git
Update the origin of your repository
# git remote add -t <Branch_Name> -f origin https://<username>@github.com/<username>/<Repo_name>.git
# git remote add -t master -f origin https://vmsnivas@github.com/vmsnivas/ansible.git
Clone your repository now.
# git clone https://vmsnivas@github.com/vmsnivas/ansible.git
Case 2: Repository with multiple branches.
Go to your git directory.
# cd /git
Create a direcotry with the name of the repository and child direcotries with the name of the branches you have.
# mkdir -p <repo_name>/{branch1,branch2,....}
# mkdir -p python/{master,notes,programs}
Go to the repo dir and initialize git.
# cd python
# git init
Set the origin of your repo.
# git remote set-url origin https://<username>@github.com/<username>/<Repo_name>.git
# git remote set-url origin https://vmsnivas@github.com/vmsnivas/python.git
Go to one of your branches and initialize git.
# cd master
# git init
Update the origin of your branch
# git remote add -t branch1 -f origin https://<username>@github.com/<username>/<Repo_name>.git
# git remote add -t master -f origin https://vmsnivas@github.com/vmsnivas/python.git
Now clone the contents of that specific branch from the repo.
# git clone -b branch1 https://<username>@github.com/<username>/<Repo_name>.git
# git clone -b master https://vmsnivas@github.com/vmsnivas/python.git

Click here to view in GitHub