Table of contents
What is Git?
Git is distributed version control system. Git keeps track of the files and changes which is made so that specific version of files can be reverted whenever needed. Git makes collaboration easier, which means multiple people can work on the same project.
Some basic commands of git
- git init : Create an empty git repository or reinitialize the existing one.
Syntax:
$ git init
- git status : Show the working tree status.
Syntax:
$ git status
- git add : Add file contents to the index/staging area.
Syntax:
$ git add [file name]
- git add . : Add all files contents to the index/staging area.
Syntax:
$ git add .
- git commit -m : Record changes to the repository with a message.
Syntax:
$ git commit -m "Your message"
For example:
$ git commit -m "my first commit"
- touch : Used to create new file.
Syntax:
$ touch [filename]
- git mv : move or rename a file, a directory, or a symlink.
Syntax: To Rename
$ git mv oldfilename newfilename
For example:
$ git mv read.md readme.md
$git commit -m "read.md renamed to readme.md"
Syntax: To Move
$ git mv filename foldername
For example:
$ git mv readme.md project_01
$git commit -m "readme.md moved to project_01 folder"
- git rm : Remove files from the working tree and from the index/staging area.
Syntax:
$ git rm [filename]
- git diff : Show change between commits, commit and working tree, etc.
Syntax:
$ git diff
- git diff --staged : Compare staging area to last commit.
Syntax:
$ git diff --staged
- git log : Show commit log.
Syntax:
$ git log
- git branch : Show all branches and shows the current branch in green color.
Syntax:
$ git branch
- git branch [newbranchname] : Creates new branch .
Syntax:
$ git branch [newbranchname]
For example:
$ git branch feature1
- git checkout : Used to switch between the branches created by the git branch.
Syntax:
$ git checkout [branch name]
- git merge : Join two or more development histories together.
Syntax:
$ git merge [branch name]
- git reset : Reset current HEAD to the specified state means when you have moved the file to the staging area and now want back
Syntax:
$ git reset HEAD [filename]
For example:
$git reset HEAD readme.md
- git push : Used to upload local repository content to a remote repository.
Syntax:
$ git push origin [branchname]