Saturday, December 21, 2019

GIT Commands

Hello All, In this blog we'll study about basic commands and terminologies in GIT .

What is GIT ?

  • GIT is most popular Version Control System used by many software development projects around the world

Few basic terminologies used in GIT

  • Repository : Repository is simply a place where the history of our work is stored.
  • Clone : Copying of remote GIT repository into local system.
  • Pull : To get latest code into our local system.
  • Add : Adding new file into GIT, which we want to commit.
  • Push : Pushing our local system files into remote GIT repository.
  • Commit : File which is stored in the repository. These files reside in the GIT directory.
  • Modify : File is modified and the latest version is not stored in the repository. These files reside in the working directory.
  • Stage : File was modified and is marked to be included in the next commit. These files reside in the staging area.

GIT commands to work

  • To get remote GIT repository into our local system for the first time
Syntax  : git clone <GIT URL>
Example : git clone https://domaiNname/branchName.git
  • To get recent changes from remote repository into our local system
Syntax  : git pull
Example : git pull
  • To push new file from local system to remote GIT repository, one has to perform below actions
Syntax  : git add <fileName>   - To add single file
          git add *            - To add multipe files
          git commit -m <commit message>
          git push

Example : Let's say we have one file with name Report.java which has to commit in remote repository.
          git add Report.java
          git commit -m "Commiting the Report.java file"
          git push

Note    : Always we should take a pull before push, to avoid conflicts.
  • To check the status of files in local system
Syntax  : git status
Example : git status

Note    : It shows the status of files which are added, modified, committed etc
  • To revert the file from our local git repository
Syntax   : git checkout <fileName> - To revert back single file to it's older git revision
           git checkout .      - To revert back all changed files
Example  : git checkout Report.java
                  (or)
           git checkout .


  • To stash our local git changes, when we take pull without undo our local file changes
Syntax  : git stash        
          git stash list   
          git stash apply  
Example : git stash        - To stash our local changes
          git stash list   - To see the list of files we stashed
          git stash apply  - To get back the stahed files
Note    : To get updated changes/pull in particluar files without loosing our changes.
  • To check git logs history
Syntax  : git log
Example : git log
Note    : Above command shows history with Commit ID, Author, Date and Commit Description

  • To exit GIT terminal
Syntax  : logout
Example : logout
Note : In this blog we have covered very few commands, will come up with branching and merging of GIT in the next blog.

GIT Commands

Hello All, In this blog we'll study about basic commands and terminologies in GIT . What is GIT ? GIT is most popular Version Cont...