Blog

  • In this blog, we'll discuss some basic and essential commands of git.

    Install Git (minimal required packages)


    On Linux:
    * For Redhat Based Distros:
    $ sudo yum install git


    * For Debian Based Distros:
    $ sudo apt-get install git


    On mac/windows:
    *go to link: http://git-scm.com/download/linux
    *download binaries and install using guided
    gui.

     

    a. To get clone from repo
        
        -    git clone <repo URL from git>

    b. Now modify some code 

        -    After modify we have to check our changes so for this type the below command

            -    git status

        -    By the git status command, it will show you all file name in which you made the changes.

    c. After seeing changes we have to commit our changes, so before commit, we have to add our code.
        
    d. To add our code we have to follow the below command

        -    git add <file name>

                or

        -    git add -A

    In the first command, it will add only the file which we mention and in second command it will add all files in which we did changes.

    e. After add, we have to commit the code to commit just follow the below command

        -    git commit -m "message to remember your changes"

    f. Now we have to just push our code on git but before push first takes pull from the git, as if any other developer push there code on git by pull command we take all the updated code and after this, we push our code, so follow the below commands for pull and push.

        -    git pull origin < your branch name>

            - It will ask your username and password of git.
        
        -    After pull now we have
    push our code by below command

                -    git push origin < your branch name> 

    g. How to create a new branch from existing branch 

        -    By default if we create a new branch it will go under master branch for this command is 

                -    git checkout -b <branchname>

        -    If you want to create a new branch under existing branch for this command is 
        
                -    git checkout -b <yourbranchname> <existingbranchname>

    h. You can switch from one branch to another by the below command.

        -    git checkout <branchname>

    i. List all of your branches in your repo, and also check your current branch:

        -    git branch

    j. After creating new branch we have to push it on the remote repo, so any other developer in your team can use it.

        -    git push origin <branchname>
     
    k.  How to rename an existing branch

        -    There are two ways to rename a branch first if you are on the same branch which you want to rename then follow the command

                -    git branch -m <new-name>

        -    If you are on some other branch then follow the below command

                -    git branch -m <old-name> <new-name>

    After above step, we have to delete the old-name remote branch and push the new-name local branch by below command

                -    git push origin :old-name new-name

    After deleting the old name branch final step is to push the rename branch as follows

                -    git push origin -u new-name

     

Tags: Server

Mobile Applications

Video Content

Bigdata & NoSQL

SaaS Applications

Miscellaneous

Archives


Alexa Certified Site Stats for www.oodlestechnologies.com