How to Setup Git

Full-Stack Developer

Hello Guys, Welcome to the world of Inception. I am bringing this tutorial to explain how to install Git and import new project into Git, make change in it and share change with other developers. Let's start

 

Installing GIT.

      a.Installing Git Window:

            https://git-scm.com/download

       b.Installing Git Ubuntu:

            sudo apt-get install git-all

Setup Git    
    

    a.Open Terminal

    b.Set a Git username and email:

        git config --global user.name "DemoUser"

        git config --global user.email "example@example.com"

    c.Confirm that you have set the Git username and email correctly:

        git config --global user.name

            Output -> DemoUser

        git config --global user.email

            Output -> example@example.com

Configure core.editor in git


a.Using Sublime Text as your editor

      Install Sublime Text 3

        Window

        Linux

b. Open Terminal.

c. Type this command:

    git config --global core.editor "subl -n -w"


Setup SSH keys in git

    Log in https://gitlab.com/

    Click on Profile icon

    Goto Settings

    SHH Keys

    Generate Key following documentation


Importing New Project

    Check out repository

        git clone /path/to/repository

    Making Changes

        Modify some files, then add their updated contents to the index:

    Add Files

        a. Add one file --> git add <filename>

        b. Add more than one file to stagging --> git add *

    Commit

        a. Before writing commit please read this documentation

        b. Basic commit message:

            git commit -m "Commit message"

        c. Commit in default text editor

            i. git commit

            ii. Default text editor will open and commit you changes

            Iii. Close text editor then return back to git bash

    Status

        a.List the files you've changed and those you still need to add or commit:

            git status

    Branches

         a.List all the branches

            git branch

        b.Switch to branch

            git checkout <branchname>

    Pull

        git pull origin <branchename>

    Push

        git push origin <branchename>

    Log

        git log

     Merge and Diff Guide

        Install Merge and Diff tool in Git

            P4Merge

                i. Download P4Merge

                ii. Extract the archive P4Merge download to /opt/p4merge:

                iii. sudo mv * /opt/p4merge

                iv. sudo ln -s /opt/p4merge/bin/p4merge /usr/local/bin/p4merge

                v. After that, add this to your ~/.gitconfig:

                    [merge]

                        tool = p4merge

                    [mergetool "p4merge"]

                        cmd = p4merge "$BASE" "$LOCAL" "$REMOTE" "$MERGED"

                        trustExitCode = true

                    [diff]

                        tool = p4merge

                    [difftool "p4merge"]

                        cmd = p4merge "$LOCAL" "$REMOTE"

            Merge Conflict

                i. If there is a merge conflict git will display something like this:

                    $ git merge branch_name

                    Auto-merging file_name

                    CONFLICT (content): Merge conflict in file_name

                    Automatic merge failed; fix conflicts and then commit the result.

                ii. git mergetool

                iii. P4merge application will open

                iv. Check change in local server and remote server. Execute change in file

                v. Save file

                vi. Add Change file

                vii. Commit changes

                viii. Pull the changes from branch

                ix. Push to branch