Git Commands and their usage

Some useful basic git commands that can help you in your works. Get to know how to use each of them well to your advantage.
Git commands - iboosthub

Some Basic git commands

  • git config
  • git init
  • git clone
  • git add
  • git commit
  • git diff
  • git reset
  • git status
  • git rm
  • git log
  • git show
  • git tag
  • git branch
  • git checkout
  • git merge
  • git remote
  • git push
  • git pull
  • git stash

How to use them

A. git config
Usage: git config -global user.name “[name]”
Usage: git config -global user.email “[email address]”
Purpose: Sets the author name and email address respectively to be used with your            commits.

B. git init
Usage: git init [repository name]
Purpose: To start a new repository.

C. git clone
Usage: git clone [url]
Purpose: Used to obtain a repository from an existing URL.

D. git add
Usage: git add [file]
Purpose: Adds a file to the staging area.
Usage: git add *
Purpose:  Purpose: Adds one or more of the staging area.

E. git commit
Usage: git commit -m “[Type in the commit message]”
Purpose: Records or snapshots the file permanently in the version history.
Usage: git commit -a
Purpose: Commits any added files with a git add command and also commits any files    that has been altered since inception.

F. gif diff
Usage: git diff
Purpose: Shows the differences in files that are yet to be staged.
Usage: git diff -staged
Purpose: Shows the differences between the files in the staging area and the latest version present.
Usage: git diff [first branch] [second branch]
Purpose: Shows the difference between two branches.

G.git reset
Usage: git reset [file]
Purpose: Unstages the file, but it preserves the file contents
Usage: git reset [commit]
Purpose: This command undoes all the commits after the specified commit and preserves the changes locally.
Usage: git reset -hard [commit]
Purpose: This command discards all history and goes back to the specified commit.

H. git status
Usage: git status
Purpose: This command lists all the files that have to be committed.

I. git rm
Usage: git rm [file]
Purpose: This command deletes the file from your working directory and stages the         deletion.

J. git log
Usage: git log
Purpose: This command is used to list the version history for the current branch.
Usage: git log -follow [file]
Purpose: lists version history for a file, including the renaming of files also.

K. git show
Usage: git show [commit]
Purpose: shows the metadata and content changes of the specified commit.

L. git tag
Usage: git tag [commit ID]
Purpose: used to give tags to the specified commit.

M. git branch
Usage: git branch
Purpose: lists all the local branches in the current repo.
Usage: git branch [branch name]
Purpose: creates a new branch
Usage: git branch -d [branch name]
Purpose: deletes the feature branch

N. git checkout
Usage: git checkout [branch name]
Purpose: used to switch from one branch to another.
Usage: git checkout -b [branch name]
Purpose: creates a new branch and also switches to it.

O. git merge
Usage: git merge [branch name]
Purpose: merges the specified branch’s history into the current branch

P. git remote
Usage: git remote add [variable name] [Remote Server Link]
Purpose: To connect local repository to the server

Q. git push
Usage: git push [variable name] master
Purpose: sends the committed changes of master branch to your remote repo.
Usage: git push [variable name] [branch]
Purpose: sends the branch commits to your remote repo.
Usage: git push -all [variable name]
Purpose: pushes all branches to your remote repo.
Usage: git push -all [variable name] :[branch name]
Purpose: deletes a branch on your remote repo.

R. git pull
Usage: git pull [Repository Link]
Purpose: fetched and merges changes on the remote server to your working directory.

S. git stash
Usage: git stash save
Purpose: temporarily stores all the modified tracked files.
Usage: git stash pop
Purpose: restores the most recently stashed files.

Usage: git stash list
Purpose: lists all stashed changesets.
Usage: git stash drop
Purpose: discards the most recently stashed changeset.

Total
0
Shares
Leave a Reply

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

Previous Post

Mozilla to discontinue Firefox password manager sync app Lockwise

Next Post
Intro to Git iboosthub

Introduction to Git

Related Posts