INTRODUCTION

GIT is a version control system used for tracking changes in computer files. We are covering different commands of GIT.  How GIT help us to manage the code changes and tracking of code changes. There are lots of command developer use every day so we are going through these commands.

Commands used for GIT.

1) Change username is GIT : 

git config --global user.name "Suraj"



2) change password in GIT : 

             git config --global user.password "12345"



3) GIT clone :

This command is used to clone or downloading the repository with URL at some specific location in your system.

>> git clone <Repository URL>




4) GIT branch : 

This git command used to list all the old and new branches


>> git branch



  1. you can create new branch.
>> git branch <branch_name>

      2. you can delete create branch.

>> git branch -d <branch_name>


5) GIT fetch : 

This command used to fetch all remote branches. 

>> git fetch





  1. fetch specific branch from remote.
>> git fetch branch_name


6) GIT checkout : 

This command is used to checkout specific branch or newly created branch on local machine.

>> git checkout <branch_name>




7)  GIT add.

This command is used to add or stage the changed file.

>> git add.



  1. add specific file 
>> git add <file_name>

8) GIT commit : 

This command is used to save your local changes by committing method. We can commits changes by providing message name.

>> git commit -m "changes added" 



For above add and commit command we have single git command below.

>> git commit -am "commit message"


9) GIT commit using amend flag : 

Sometime we forgot to do a little change , for which we need to commit code with new message. So for developer it is not good practice to have multiple commits and it is difficult to find the changes with commit if you have multiple commits. To avoid multiple commits we have below command to commit into last commit message.

>>git add.
>>git commit --amend --no-edit

no-edit flag allows us to apply changes in our last commit without changing the commit message.


10) Remove File from a commit : 

Sometime we commit a file which is not a part of change or some stub changes in your commits , we can remove such file from your commit using below git command.

>> git reset HEAD <file_name>



11) GIT push : 

This command is used to push your local changes to remote repository. After committing your local changes we can use git push command to push your changes.

>> git push


12) GIT status : 

This command is used if you have done some local changes and you need to validate the changes. Sometimes you have done  lots of changes and you forgot the file name so with the help of git status we can immediately find the changed files.

>> git status


13) GIT reset : 

This command is used to undo your local changes to your state of GIT repository.

>> git reset --hard

14) GIT revert : 

This command is used to revert any specific commit from committed.

>> git revert <commit_id>



15) GIT merge : 

This is command is used to merge specific branch to current branch.
e.g. If we have checkout on  branchA and we need to merge branchB to branchA , we can use this command.

>> git merch branchB


16) GIT remote : 

This command is used to connect your local to remote repository.

>> git remote add origin <git_repository_name>



17) GIT pull : 

This command is used to pull the code changes from the remote repository to your local repository.

>> git pull 
  1. Pull from specific branch.
>> git pull <branch_name>


18) GIT stash :

If you don't want to make a commit of half-done work. Git stashing allows you to do so. The git stash command enables you to switch branches without committing the current branch.

>> git stash
  1. If you want to stash changes with message
>> git stash save

      2. If you want to list the stashed changes.

>> git stash list

     3. If you want to discard your stashed changes

>> git stash drop

19) GIT diff :

This command is used to get the difference of branch or file.

>> git diff first_branch second_branch

20)  GIT clean :

This command is used to clean the untracked files and directories.

>> git clean -f  OR git clean -fd



21) GIT log : 

This command is used to track the particular file changes. Show the commits of the file and who did the changes and at what time use git log command.

>> git log --follow -- <file_name>

  1. See the history in the Graph : 
>> git log --all --decorate --online --graph

22) GIT tag : 

This command is used to tag a release /commit in a repository if it is important. This command is used to when you want to point to specific releases.

>> git tag


23) GIT init : 

This command is used to start new repository.

>> git init


24) GIT rm :

This command is used to remove file or collection of files.

>> git rm <file_name>

Above GIT commands are useful for developer. You can use above commands in your daily git use. Git commands will help you to track your code properly and make developers time efficient. GIT is a hero that helps us handle possible problems that may occur while working on a software project.

About us

I am Suraj Ladda and working as Software Developer in IT industry.

Contact us

surajladda07@gmail.com