Frequently used GIT Commands

Views: 193   

1.) User Details
To configure the name and email address to be used with commits.

[email protected]:~# git config --global "userName"
[email protected]:~# git config --global "mailId"

2.) Git clone
To clone a copy of a local repository:

[email protected]:~# git clone /path/to/repository

/path/to/repository we can get from page HTTPS icon

3.) checkout -b newBranch
To create new branch on top a branch say X, do

 [email protected]:~#  git checkout -b newBranch

4.) git branch
To know our current branch

[email protected]:~#  git branch

5.) git pull origin brnachname
To pull branch code present on server to our machine

[email protected]:~#  git pull origin branchname

6.) git status
To know which all programs are updated in our local machine

[email protected]:~#  git status

7.)git add program
To mark the program to be added to server repository

[email protected]:~#  git add program

8.) git commit -m "added file x"
To commit the changes, -m is message that gets displayed

[email protected]:~#  git commit -m "added file x"

9.) git push origin branchname
Push changes to branchname of remote repository

[email protected]:~#  git push origin branchname

10.) git fetch origin
If we wanted to drop all our local changes and fetch the latest from the server

[email protected]:~#  git fetch origin

11.) git grep "hello"
It searches the current branch for hello

[email protected]:~#  git grep "hello"

12.) git diff sourcebranch targetbranch
It shows changes, before merging:

[email protected]:~#  git diff sourcebranch targetbranch

13.) git diff
Shows all the merge conflicts:

[email protected]:~#  git diff

14.) git push --tags origin
It Pushes all tags to remote repository

[email protected]:~#  git push --tags origin

15.) git merge branchname
It merges branchname into our active branch:

[email protected]:~# git merge branchname
On By