In order to override this with a different name or e-mail address for specific projects, you can run the command without the –global option when you’re in that project.

If git prompts you for a username and password you could be using the HTTPS clone for your repository instead of your SSH key passphrase. The SSH based URL looks like - git@github.com:user/repo.git. Follow the steps below to switch it to SSH.

Verify the remote that a local repo is mapped to

$ git remote show
# or $ git remote

Verify the remote URL that a local repo is mapped to

$ git remote -v

Change the remote URL that local repo is mapped to

$ git remote set-url origin git://new.url.here

Push all local branches that have the same name on the remote. This means potentially many different branches will be pushed, including those that you might not even want to

$ git config --global push.default matching

Push only the current working branch if it has the same name on remote

$ git config --global push.default simple

Branches

Get a list of all the branches

$ git branch -a

Create a branch and switch to it at the same time

$ git checkout -b <branchName>

Create a branch, switch to it and set the tracking/upstream branch
$ git checkout -b --track origin/

$ git reset <sha1-commit-id> #Undoes the commit after sha1-commit-id#and keeps the changes in working directory

Rearrange commits

$ git rebase -i

Rebase your last 2 local commits
$ git rebase -i HEAD~2

Abort a rebase

$ git rebase --abort

Move to an old commit

$ git reflog

Suppose the old commit that you want to go back to was HEAD@{5} in the ref log

$ git reset --hard HEAD@{5}

Go back to the previous commit

$ git reset --hard HEAD~1

Finding commits

Find a commit with text “text to find”

$ git log --grep="text to find" --pretty=oneline

Create patch

Creating a patch

$ git diff > <name>.patch

Stash your work

$ git stash

Stash work with comment

$ git stash save <comment>

List the stashes

$ git stash list

Apply a stash

$ git stash apply #Applies the stash at the top$ git stash apply stash@{n}#Applies the stash at 'n' and keeps it in the stash stack $ git stash pop stash@{n}#Applies the stash at 'n' and removes it in the stash stack

On trying to add the SSH key to the ssh-agent you can get the following error: ‘Could not open connection to your authentication agent’. You need to start ssh-agent before you can run the ssh-add command by running:
$ eval `ssh-agent -s`

Once the key has been added git should not ask for the key pass phrase on every push/pull.