Skip to content

Instantly share code, notes, and snippets.

@pavankjadda
Last active November 20, 2018 05:07
Show Gist options
  • Save pavankjadda/ef3a52a05c2c77aab7eafd8061531226 to your computer and use it in GitHub Desktop.
Save pavankjadda/ef3a52a05c2c77aab7eafd8061531226 to your computer and use it in GitHub Desktop.
Git Commands and Tips

Git Commands and Tips

Enable Git autocomoplete in macOS or Ubuntu

  1. Download git autocompletion script using following CURL command
curl https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash -o ~/.git-completion.bash
  1. Open ~/.bash_profile file (~/.bash_rc if use Linux) and add the following
if [ -f ~/.git-completion.bash ]; then
  . ~/.git-completion.bash
fi
  1. Then execute source ~/.bash_profile command in terminal

Create new branch from current/existing branch

Create new branch from existing branch

git checkout -b <new_branch> <current_branch>

Delete Remote and local branches from command lind

Delete local and remote branches through commandline

    #Delete local branch
    git branch -d <branch_name>

    #Delete remote branch
    git push --delete <remote_name> <branch_name>

Setting Global Username and Password

Use following commands to store git credentials permanently on macOS or Ubuntu

Config to use global credentials store

$ git config --global credential.helper store
$ git pull

Store password in Cache for 1 year

$ git config --global credential.helper 'cache --timeout=31557600'

Pushing specific repository as different user

Following commands will prompt for username and password

git config --local credential.helper ""
git push origin master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment