GIT Basic Command & Git Command Flow chart
Git config:This command sets the author name and email address respectively to be used with
your commits.
$ git config –global user.name “[name]”
$ git config –global user.email “[email address]”
Example:
$ git config –global user.name KrishnaPatel
$ git config –global user.email patelkisu707@gmail.com
Git init:
This command is used to start a new repository.
$ git init [repository name]
Example:
$ git init Git_Learning
Git clone:
This command is used to obtain a repository from an existing URL.
$ git clone [url]
Example:
$ git clone http://github.com/PatelKrishna123/Git_Learning
Git add:
This command adds a file to the staging area.
$ git add [file]
Example:
$ git add index.html
This command adds one or more to the staging area.
$ git add –AGit Commands
Krishna Patel
Git commit:
This command records or snapshots the file permanently in the version history.
$ git commit –a –m “[Type in the commit message]”
Example:
$ git commit –a –m “Initial commit”
Git diff:
This command shows the file differences which are not yet staged.
$ git diff
This commands shows the differences between the files in the staging area and the
latest version present.
$ git diff --staged
This command shows the differences between the two branches mentioned.
$ git diff [first branch] [second branch]
Example:
$ git diff master feature1
Git reset:
This command upstages the file, but it preserves the file contents.
$ git reset [file]
Example:
$ git reset index.html
This command undoes all the commits after the specified commit and preserves the
changes locally.
$ git reset [commit]
Example:
$ git reset 09bb8e3f996eaf9a68ac5ba8d8fceb08641e7
This command discards all history and goes back to the specified commit.
$ git reset –hard [commit]
Example:Git Commands
Krishna Patel
$ git reset –hard 09bb8e3f996eaf9a68ac5ba8d8fceb08641e7
Git status:
This command lists all the files that have to be committed.
$ git status
Git rm:
This command deletes the file from your working directory and stages the deletion.
$ git rm [file]
Example:
$ git rm log.log
Git log:
This command is used to list the version history for the current branch.
$ git log
This command lists version history for a file, including the renaming of files also.
$ git log –follow [file]
Example:
$ git log –follow contects.html
This command lists the limited logs.
$ git log –[Number of commit you need to show added in last]
Example:
$ git log –1
Git show:
This command shows the metadata and content changes of the specified commit.
$ git show [commit]
Example:
$ git show 09bb8e3f996eaf9a68ac5ba8d8fceb08641e7Git Commands
Krishna Patel
Git tag:
This command is used to give tags to the specified commit.
$ git tag [commitID]
Example:
$ git tag 09bb8e3f996eaf9a68ac5ba8d8fceb08641e7
Git branch:
This command lists all the local branches in the current repository.
$ git branch
This command creates a new branch.
$ git branch [branch name]
Example:
$ git branch feature1
This command deletes the feature branch.
$ git branch –d [branch name]
Example:
$ git branch –d feature1
Git checkout:
This command is used to switch from one branch to another.
$ git checkout [branch name]
Example:
$ git checkout feature1
This command creates a new branch and also switches to it.
$ git checkout –b [branch name]
Example:
$ git checkout –b flaskImplemntationGit Commands
Krishna Patel
Git merge:
This command merges the specified branch’s history into the current branch.
$ git merge [branch name]
Example:
$ git merge feature1
Git remote:
This command is used to connect your local repository to the remote server.
$ git remote add [variable name] [Remote Server Link]
Example:
$ git remote add origin https://github.com/PatelKrishna123/Git_Learning.git
Git push:
This command sends the committed changes of master branch to your remote
repository.
$ git push [variable name] master
Example:
$ git push origin master
This command sends the branch commits to your remote repository.
$ git push [variable name] [branch]
Example:
$ git push origin feature1
This command pushes all branches to your remote repository.
$ git push –all [variable name]
Example:
$ git push –all origin
This command deletes a branch on your remote repository.
$ git push [variable] : [branch name]
Example:Git Commands
Krishna Patel
$ git push origin : feature1
Git pull:
This command fetches and merges changes on the remote server to your working
directory.
$ git pull [Repository Link]
Example:
$ git pull https://github.com/PatelKrishna123/Git_Learning.git
Git stash:
This command temporarily stores all the modified tracked files.
$ git stash save
This command restores the most recently stashed files.
$ git stash pop
This command lists all stashed change sets.
$ git stash list
This command discards the most recently stashed change set.
$ git stash drop
Git touch:
This command used to create any type of file.
$ git touch [file name]
Example:
$ git touch index.html
Comments
Post a Comment