Thursday, April 20, 2017

GIT - Source Control System in Action!

       If you are wondering how to get GIT Source or Version Control System working within minutes, you have landed to the right page. We'll go step by step on how to get GITlab appliance from Turnkey UP and running in your local environment with GIT over HTTP enabled. You'll also learn how to create new projects, add existing projects and keep track of your projects.

Requirements:
- TurnKey GITLab appliance
- VMWare/Virtual Box Client Setup in your local machine
- CentOS 7 VM as GIT client.

Lets start.
  • Download Turnkey Gitlab OVA file from https://www.turnkeylinux.org/gitlab  and run it with VMWare workstation or vSpher
  •  Increase memory of the appliance to at least 2GB and restart.
  •  As the prompt asks, set your email id (user login for git HTTP), password, root password, mysql root password etc.
  •             You can ignore default backup scheme of Turnkey.
      Screen will provide you with login URLs:

    ·         Go to web to access GIT HTTP.
    ·         Add new project


    By default there will be only one group “Administrator” where you can create first project.
    If you want to create different group, go to Groups on left menu and create another one.


    ·         Create SSH Key for access from local machine to GIT Server
    a.       To generate a new SSH key pair, use the following command:
    Git Bash on Windows / GNU/Linux / macOS:
    ssh-keygen -t rsa -C "your.email@example.com" -b 4096
    Windows:
    Alternatively on Windows you can download PuttyGen and follow this documentation article to generate a SSH key pair.
    b.      Next, you will be prompted to input a file path to save your SSH key pair to.
  • If you don't already have an SSH key pair use the suggested path by pressing enter. Using the suggested path will normally allow your SSH client to automatically use the SSH key pair with no additional configuration.
    If you already have a SSH key pair with the suggested file path, you will need to input a new file path and declare what host this SSH key pair will be used for in your .ssh/config file, see Working with non-default SSH key pair paths for more information.
    a.       Once you have input a file path you will be prompted to input a password to secure your SSH key pair. It is a best practice to use a password for an SSH key pair, but it is not required and you can skip creating a password by pressing enter.
    Note: If you want to change the password of your SSH key pair, you can use ssh-keygen -p <keyname>.
    b.      The next step is to copy the public SSH key as we will need it afterwards.
    To copy your public SSH key to the clipboard, use the appropriate code below:
    macOS:
    pbcopy < ~/.ssh/id_rsa.pub
    GNU/Linux (requires the xclip package):
    xclip -sel clip < ~/.ssh/id_rsa.pub
    Windows Command Line:
    type %userprofile%\.ssh\id_rsa.pub | clip
    Git Bash on Windows / Windows PowerShell:
    cat ~/.ssh/id_rsa.pub | clip
    c.       The final step is to add your public SSH key to GitLab.
    Navigate to the 'SSH Keys' tab in your 'Profile Settings'. Paste your key in the 'Key' section and give it a relevant 'Title'. Use an identifiable title like 'Work Laptop - Windows 7' or 'Home MacBook Pro 15'.
    If you manually copied your public SSH key make sure you copied the entire key starting with ssh-rsa and ending with your email.



    ·        
    Set GIT global user in local machine as yourself (set your email exactly same as with GIT Profile)#git config --global user.name “Sam”#git config --global user.email sam@xyz.com
·         GIT Clone the repository created to your local machine.
#cd /root/
#git clone git@<GIT-Server-IP>:gitlab-admin/virtualhost-test1.git
·         Add a new file to GIT repo.
#cd test1
#ls –al   #check for .git folder
#touch newfile1
#git add newfile1
#git push –u origin master 
·         Add existing directory/project to GIT repo.
Create a new project in GIT “newproject-test1”
In your local machine, do following:
#cd existingdir1
#git init       //initialize existing project as GIT project
#git add .    //add everything under the project directory to GIT ready to be committed
#git commit –m “Commit new project for push to GIT server”

//add remote GIT server as default ready to push changes to Master
#git remote add origin git@<GIT-Server-IP>:gitlab-admin/newproject-test1.git
//verify connectivity to remote GIT project
#git remote –v  
//push changes to GIT Server Master project
#git push –u origin master