Git on the command line

 [1]. Configure Git

 To start using Git from your computer, you’ll need to enter your credentials (user name and email) to identify you as the author of your work. The user name and email should match the ones         you’re using on GitLab.

    In your shell, add your user name:

      git config --global user.name "your_username"

    And your email address:

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

    To check the configuration, run:

        git config --global —list

[2]. To clone git@gitlab.com:gitlab-org/gitlab.git via SSH:

         git clone git@gitlab.com:gitlab-org/gitlab.git

 [3]. Git init, add , push
    
     Convert a local directory into a repository 

         git init

     Add a remote repository

         git remote add origin <git@gitlab.com:username/projectpath.git

     Add and commit local changes

      git add <file-name OR folder-name>
   git commit -m "COMMENT TO DESCRIBE THE INTENTION OF THE  COMMIT”

    Add all changes to commit
   
       git add .
   git commit -m "COMMENT TO DESCRIBE THE INTENTION OF THE COMMIT"

    To push all local commits (saved changes) to the remote repository:

       git push <remote> <name-of-branch>

    For example, to push your local commits to the master branch of the origin remote:

      git push origin master

[4]. Git branch

    Create a branch

        git checkout -b <name-of-branch>

    Switch to the master branch

       git checkout master

    Work on an existing branch

      git checkout <name-of-branch>

    Delete all changes in the branch

    To delete all local changes in the branch that have not been added to the staging area, and leave             unstaged files/folders, type:

     git checkout .

    Note that this removes changes to files, not the files themselves.

    Unstage all changes that have been added to the staging area
    To undo the most recently added, but not committed, changes to files/folders:

    git reset .

    Undo most recent commit
    To undo the most recent commit, type:
  • Check commit before reset 
    • git log --oneline
    • ff31686 fourth commit ac79570
    • third commit b6eb67c second commit b20d416 first commit
  • Git Reset 
    • git reset ac79570
    • git reset --hard master
    • git reset --hard develop
    • git reset --hard ac79570

    This leaves the changed files and folders unstaged in your local repository.

    Warning: A Git commit should not usually be reversed, particularly if you already pushed it to the         remote repository. Although you can undo a commit, the best option is to avoid the situation                 altogether by working carefully.

[5]. Merge a branch with master branch

    When you are ready to make all the changes in a branch a permanent addition to the master              branch, you merge the two together:

    git checkout <name-of-branch>
   git merge master 

Comments

Popular posts from this blog

Java : Variables Declaring

Install DNF in RHEL/CentOS 7

SQL Self JOIN