Monday, April 16, 2018

Frequently used git command notes

Occasionally, I forgot the command or its functionality and checked it on GitPro. So, in order to avoid that I'm take a note of frequently used command here.
    
        $ git fetch origin
    

Explanation :

First of all, this command looks up which server "origin" is. Then fetches any data from it that you don't have yet, and updates your local database. For instance origin/master pointer to its new, more up-to-date position.

When? :

My coworker does something new to git server, like, push the modification, create new branch. When I notice there is no branch in remote-tracking branch shown as "origin/{branch name}" you friends said he created and pushed. Before quarreling, just simply type this command.
    
        $ git branch <new branchName> origin/<new branchName>
         set up to track remote branch DecisionSupport from origin.
        $
    

Explanation :

It creates new branch in local from remote-tracking branch. Nevertheless, It won't change you workspace.

When?? :

You fetched new branch from server and it's visible with " git branch -a ", yet invisible with " git branch". Consequently, you can check new branch in local space.
    
        $git checkout <branchName> 
        Switched to branch '<branchName>'
        Your branch is up-to-date with 'origin/<branchName>'.
    

Explanation :

It's change branch of your workplace to new branch.

When ? :

When you make up your mind to work on new branch.
    
        $git diff --name-only <commit number A> <commit number B>
    

Explanation :

It shows files which is added or deleted or modified between commit A and commit B.

When ? :

When you are desperate to know which files were changed between commit A and commit B.
    
        $git branch -d <branch name>
    

Explanation :

It deletes specified branch from local branch.

When ? :

You no longer have any feelings for that branch.
    
        $git checkout <branch name>
        $git merge origin/<branch name>
    

Explanation :

Reflect modification from remote-tracking branch into local branch tree.

When ? :

When you want to reflect modification on remote server into your local branch.
    
        $git log -1 origin /<branch name>
        $git log -1 HEAD 
    

Explanation :

First command shows you the commit of remote branch. It goes without saying that you should type 'git fetch origin' beforehand.
Second one shows commit of your local branch.
Incidentally, 'HEAD' means 'Pointer to the local branch you're currently work on.

When ? :

When you want to know whether there is progress in remote branch compare to local.

No comments:

Post a Comment