Other

Learn All Git Commands With Description And Example

What is Git and Git Commands?

Git is a distributed source control or version control system. You might me wondering about to heard source control or version control don’t worry? Source control or version control is cloud based code managing and tracking process. So We can tracks every change in our code throw the git commands.

  • Git is used to tracking changes in the source code
  • The distributed version control tool is used for source code management
  • It allows multiple developers to work together
  • It supports non-linear development through its thousands of parallel branches

Git Commands:

We can you Git in many different ways. Its supports many graphical user interfaces and command -line tools. To run Git commands on command-line tools.

These are following commands of Git that is used via command-line.

  1. Git Config
  2. Git Init
  3. Git Add
  4. Git Status
  5. Git Commit
  6. Git Fetch
  7. Git Pull
  8. Git Push
  9. Git Clone
  10. Git Stash
  11. Git Head
  12. Git Origin Master
  13. Git Remote
  14. Git Checkout
  15. Git Branch
  16. Git Rebase
  17. Git Merge/Merge Conflict
  18. Git Revert
  19. Git Ignore

1) Git config command

Git config command is use to configures the user. This is the necessary and first command that is used on the Git command line. Git config command sets the author email address , user name to be used with your commits. This is also used in some other scenarios.

Syntax

  1. $ git config –global user.name “your name”  
  2. $ git config –global user.email “your email id”  

Please replace “your email id” with your proper email same things do for name

2) Git Init command

Before run on Git you will run first Git Init command. This command will create a new blank repository also this command make an existing project as a Git project. Other Git commands run inside the repository.

This command creates a .git subdirectory in the current working directory. This newly created subdirectory contains all of the necessary metadata.

Syntax

  1. $ git init  

The above command will create an empty .git repository.

3. Git Add Command

This command is used to add a file or all files contents to the Index or staging Area. Git Add command get all change content of the working tree and update to the staging area and prepares the staged content for the next commit.

This command is a main or core part of Git technology. It typically adds one file at a time, but there some options are available that can add more than one file at once.

This git command can be run one or many times before making a commit.

for add single file use following command

$ git add <File name>  

for add all file use following command

$ git add -A  
Or
$ git add .

To add all modify and deleted file use following commad

$ git add -u 

Note – For undo add file bellow command will use

$ git reset <filename>  

4. Git Status command

This command is allows to see the change, tracked and untracked on the files. Status command is used to display the state of the repository. This command will list down all file where any change happend.

When run this command this show list of file in red colour means that all files are not index for commit and after add command this show list of file in green colour means file are ready to commit

$ git status  

5. Git Commit command

This command will commit the changes and generate a commit-id.

$ git commit -m "Commit message."  

The -m option of allow you to write the some commit message on the command line.

6. Git Fetch Command

Visited 14 times, 1 visit(s) today

Leave a Reply

Your email address will not be published. Required fields are marked *