Header Ads

Git commands real time explanation | Git commands for beginners | git commands for software engineers

 Git Commands :




1. git config : This git command will set the name and email to be used with your commits.

Command Syntax : 

  • git config --global user.name "name"
  • git config --global user.email "email"

Example: 

  • git config --global user.name "shyamprasad"
  • git config --global user.name "shyamprasad@abc.com"

2. git init : This git command will be used to create the new repository in your machine.

Command Syntax : 
  • git init "repository name"
Example:
  • git init SampleAppDemo

3. git clone : It is used to clone an existing repository using URL.

Command Syntax :
  • git clone "URL"
Example :
  • git clone https://github.com/shyam/example.git

4. git add  : It is used to add the newly created files or modified files to staging area.

Command Syntax :
  • git add "filename"
Example :
  • git add test.js

5. git commit : It is used to commit the files from staging area to main repository.

Command Syntax :
  • git commit -m "commit message"
Example :
  • git commit -m "print statements are added to check logs"

6. git diff : It is used to know the file differences which are not staged.

Command Syntax :
  • git diff 
Example :
  • git diff
To know the difference between files in staging area and previous version.
  • git diff  - staged
To know the difference between two branches.
  • git diff  firstbranchname secondbranchname

7. git reset : It is used to unstage the files but preserves the file contents.

Command Syntax :
  • git reset "filename"
Example :
  • git reset file1.js

This command undo all the commits after the specified commit and preserves the changes locally.
  •  git reset "commit id"
This command discards all history and goes back to the specified commit.
  • git reset --hard [commit id]  

8. git status: This command is used to lists all the files that needs to be committed.

Command Syntax :
  • git status
Example :
  • git status

9. git rm : This command is used to deletes the file from your working directory and stages the deletion.

Command Syntax :
  • git rm "filename"
Example :
  • git rm test1.js

10. git log : This command is used to list the version history for the current branch.

Command Syntax :
  • git log
Example :
  • git log
With multiple params: 
  •  git log -follow "filename"

11. git show : This command shows the metadata and content changes of the specified commit.

Command Syntax :
  • git show "commit id"
Example :
  • git show hhd7887474fgdfgdfgewrtrtrttvsdfc

12. git branch : This command is used to lists all the local branches in the current repository.

Command Syntax :
  • git branch 
Example :
  • git branch
One more we have : git branch "branchname"


13. git checkout : It is used to checkout the branch to our local repository.

Command Syntax :
  • git checkout "branchname"
Example :
  • git checkout SampleAppDemo
One more we have : This command creates a new branch and also switches to it.
  • git checkout -b "branchname"

14. git merge : This command merges the specified branch’s history into the current branch.

Command Syntax :
  • git merge "branchname"
Example :
  • git merge demo1

15. git remote : This command is used to connect your local repository to the remote server.

Command Syntax :
  • git remote add "variablename" "remote server link"
Example :
  • git remote add origin https://github.com/shyam/example.git

16. git push : This command sends the committed changes of master branch to your remote repository.

Command Syntax :
  • git push "variablename" master
  • git push "variablename" branchname        
  • git push  -all"variablename"
Example :
  • git push origin master
  • git push origin test1demo

17. git pull : This command fetches and merges changes on the remote server to your working directory.

Command Syntax :
  • git pull "Repo link"
Example :
  • git pull https://github.com/shyam/example.git

18. git stash : This command temporarily stores all the modified tracked files.

Command Syntax :
  • git stash save
Example :
  • git pull https://github.com/shyam/example.git
git stash pop : This command restores the most recently stashed files.
git stash list : This command lists all stashed changesets.
git stash drop : This command discards the most recently stashed changeset.

1 comment:

  1. The King Casino - Atlantic City, NJ | Jancasino
    Come on in the casino-roll.com King https://octcasino.com/ Casino for fun, no wagering requirements, https://deccasino.com/review/merit-casino/ delicious dining, https://deccasino.com/review/merit-casino/ and enjoyable casino gaming all at the heart of Atlantic City. https://jancasino.com/review/merit-casino/

    ReplyDelete

Powered by Blogger.