Frequently used GIT Commands
1.) User Details
To configure the name and email address to be used with commits.
userName@hostName:~# git config --global user.name "userName"
userName@hostName:~# git config --global user.email "mailId"
2.) Git clone
To clone a copy of a local repository:
userName@hostName:~# git clone /path/to/repository
/path/to/repository we can get from https://bitbucket.org/projectName/overview page HTTPS icon
3.) checkout -b newBranch
To create new branch on top a branch say X, do
userName@hostName:~# git checkout -b newBranch
4.) git branch
To know our current branch
userName@hostName:~# git branch
5.) git pull origin brnachname
To pull branch code present on server to our machine
userName@hostName:~# git pull origin branchname
6.) git status
To know which all programs are updated in our local machine
userName@hostName:~# git status
7.)git add program
To mark the program to be added to server repository
userName@hostName:~# git add program
8.) git commit -m "added file x"
To commit the changes, -m is message that gets displayed
userName@hostName:~# git commit -m "added file x"
9.) git push origin branchname
Push changes to branchname of remote repository
userName@hostName:~# git push origin branchname
10.) git fetch origin
If we wanted to drop all our local changes and fetch the latest from the server
userName@hostName:~# git fetch origin
11.) git grep "hello"
It searches the current branch for hello
userName@hostName:~# git grep "hello"
12.) git diff sourcebranch targetbranch
It shows changes, before merging:
userName@hostName:~# git diff sourcebranch targetbranch
13.) git diff
Shows all the merge conflicts:
userName@hostName:~# git diff
14.) git push --tags origin
It Pushes all tags to remote repository
userName@hostName:~# git push --tags origin
15.) git merge branchname
It merges branchname into our active branch:
userName@hostName:~# git merge branchname