Setting up user
git config --global user.name "Srikanth Bemineni"
git config --global user.email "firstname.lastname@example.org"
git config --global credential.helper cache
git config --global credential.helper 'cache --timeout=3600'
Setting up GitHub key
ssh-keygen -t rsa -C "email@example.com"
please install xclip it
xclip -sel clip &amp;amp;lt; ~/.ssh/id_rsa.pub
Create Project – To make the existing project root folder managed by the Git repository or to start a new project
git init .
Clone Project(checkout) – To check out a project.
We use the git URL in the form git:\\…
git clone git://github.com/bemineni/eldam.git
Add – To add new files to the project
git add [filename];
The below command will add any new file that hasn’t been added to the current project
git add .
Status – To get status of the current repository
-s Short output
git status -s
diff – To get diff of the changes
Show both staged and unstaged changes comparing with the head revision
git diff HEAD
To show the short status output of the diff
git diff --stat
commit – To commit the changes
git commit -m "Message"
This will open the default editor to enter the message.
Will get all the changes logs with respect to the branch
A compact version of the log output.
git log --oneline
Will show a graph of the branches and changes
git log --oneline --graph
reset – To reset the changes. Commit will not commit these changes
git reset HEAD [filename]
Remove – To remove the file from git
Move – If you want to move the file and add it to the git
tag – To tag the current head
git tag -a
To get all the tags from the remote
git fetch origin --tags
To find out the current branch details use the below command
To find out last commits on all the branches.
git branch -v
Create a new Branch.
Switch or checkout to a branch
The branch should have been created using the previous command
git checkout [name of new or existing branch]
The -b creates a new branch and switches to the new branch.
git checkout -b
Delete a branch
git branch -d
This push the changes to the remote repository and delete the branch
git push [remote-name] :[branchname]
This command will merge the changes and move to the branch that was used to create this branch.
List remote – This will be used to manage remote attribute
lists all of the remote repositories
git remote -v
$ git remote -v
github firstname.lastname@example.org:bemineni/baamv.git (fetch)
github email@example.com:bemineni/baamv.git (push)
Add a new remote URL
git remote add [name] [url]
$git remote add origin firstname.lastname@example.org:something/something.git
Remove remote repositories
This command will remove the remote repositories
git remote rm [name]
$git remote rm github
Renaming an alias
git remote rename [old_name] [new_name]
$git remote rename github origin
Updating the new URL for the remote repository
git remote set-url
git remote set-url github email@example.com:something/something.git
Fetch -To get updates from a remote branch.
To synchronize your repository with a remote repository, fetching all the data it has into your branch reference locally for merging
git pull -> This will fetch from the remote and merge with the current branch locally
Push – To update a remote repository with the changes you’ve made locally.
It will take what your [branch] looks like and push it to be [branch] on the remote, if possible. If someone else has pushed since you last fetched and merged, the Git server will deny your push until you are up to date.
How to update your project which has already been modified from the current master branch. (similar to SVN update)
When you have changed on your working copy, from the command line do:
This will stash your current changes and clear your status
This will pull changes from an upstream branch. Make sure it says fast-forward in the report. If it doesn’t, you are probably doing an unintended merge
git stash pop
This will apply stashed changes back to working copy and remove the changes from stash unless you have conflicts. In the case of conflict, they will stay in the stash so you can start over if needed.
If you need to see what is in your stash
git stash list