Setting up user
git config --global user.name "Srikanth Bemineni"
git config --global user.email "srikanth.bemineni@gmail.com"
git config --global credential.helper cache
git config --global credential.helper 'cache --timeout=3600'
Setting up GitHub key
https://help.github.com/articles/generating-ssh-keys
ssh-keygen -t rsa -C "srikanth.bemineni@gmail.comi"
please install xclip it
xclip -sel clip < ~/.ssh/id_rsa.pub
Git commands
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
git status
-s Short output
git status -s
diff – To get diff of the changes
git diff
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.
git commit
log
Will get all the changes logs with respect to the branch
git log
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
git rm
Move – If you want to move the file and add it to the git
git mv
tag – To tag the current head
git tag -a
To get all the tags from the remote
git fetch origin --tags
Git Branching
To find out the current branch details use the below command
git branch
To find out last commits on all the branches.
git branch -v
Create a new Branch.
git 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]
Merge branches
This command will merge the changes and move to the branch that was used to create this branch.
git merge
Git Remote
List remote – This will be used to manage remote attribute
lists all of the remote repositories
git remote -v
Example:
$ git remote -v
github git@github.com:bemineni/baamv.git (fetch)
github git@github.com:bemineni/baamv.git (push)
Add a new remote URL
git remote add [name] [url]
Example
$git remote add origin git@github.com:something/something.git
Remove remote repositories
This command will remove the remote repositories
git remote rm [name]
Example
$git remote rm github
Renaming an alias
git remote rename [old_name] [new_name]
Example
$git remote rename github origin
Updating the new URL for the remote repository
git remote set-url
Example
git remote set-url github git@github.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 fetch
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.
git push
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:
git stash
This will stash your current changes and clear your status
git pull
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