Git Configuration
Connecting to GitHub with SSH
You can connect to GitHub using the Secure Shell Protocol (SSH), which provides a secure channel over an unsecured network.
Checking for existing SSH keys
$ ls -al ~/.ssh # Lists the files in your .ssh directory, if they exist
Generating a new SSH key
$ ssh-keygen -t ed25519 -C "your_email@example.com"
When you’re prompted to “Enter a file in which to save the key,” press Enter. This accepts the default file location.
Note: If you are using a legacy system that doesn’t support the Ed25519 algorithm, use:
$ ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
```
> Enter a file in which to save the key (/c/Users/you/.ssh/id_algorithm):[Press enter]
At the prompt, type a secure passphrase. For more information, see "Working with SSH key passphrases."
> Enter passphrase (empty for no passphrase): [Type a passphrase]
> Enter same passphrase again: [Type passphrase again]
```
Adding SSH key to the
ssh-agent
Ensure the ssh-agent is running. Start it manually:
# start the ssh-agent in the background $ eval "$(ssh-agent -s)" > Agent pid 59566
Add your SSH private key to the ssh-agent. If you created your key with a different name, or if you are adding an existing key that has a different name, replace id_ed25519 in the command with the name of your private key file.
$ ssh-add ~/.ssh/id_ed25519
Add the SSH key to your account on GitHub.
Copy the SSH public key to your clipboard.
$ clip < ~/.ssh/id_ed25519.pub # Copies the contents of the id_ed25519.pub file to your clipboard
In the upper-right corner of any page, click your profile photo, then click
Settings
In the Access section of the sidebar, click
SSH and GPG keys
.Click
New SSH key
orAdd SSH key
.In the Title field, add a descriptive label for the new key. For example, if you’re using a personal laptop, call this key “Personal Laptop”.π‘
Paste your key into the Key field.
Click
Add SSH key
.
- While cloning/pulling/pushing code from remote use your username and generated token when prompted for username and password respectively.
- On Windows this stores your credentials in the Windows credential store which has a Control Panel interface where you can delete or edit your stored credentials. With this store, your details are secured by your Windows login and can persist over multiple sessions.
Initialize a new local repository
$ git init
Developer Configuration
If you would not like to provide credentials for every “repo” operations you could cache them. The Git credential cache runs a daemon process which caches your credentials in memory and hands them out on demand.
$ git config --global credential.helper manager
Configure the author name and email address to be used with your commits:
$ git config --global user.name "LAST_NAME.FIRST_NAME" $ git config --global user.email "WORK_EMAIL"
Normalize your line endings:
$ git config --global core.autocrlf false
Colorized output:
$ git config --global color.ui auto
Setup KDiff as the merge tool:
$ git config --global --add merge.tool kdiff3 $ git config --global --add mergetool.kdiff3.path "C:/Program Files/KDiff3/kdiff3.exe"
Setup proxies to work with Git:
- Option1: Git Proxy without Cntlm: (Not secure as our credentials are being sent “over the wire”)
$ git config --global http.proxy http://MyUserID:MyPassword@www-proxy.company.com:80 $ git config --global https.proxy http://MyUserID:MyPassword@www-proxy.company.com:80
- Option2: Git Proxy w/ Cntlm: (Safe since our passwords are encrypted. Generic enough to be used with a host of tools like NPM, Git, AWS, Eclipse, Docker etc.)
$ git config --global http.proxy http://localhost:3128 $ git config --global https.proxy http://localhost:3128
- Option1: Git Proxy without Cntlm: (Not secure as our credentials are being sent “over the wire”)
Display current settings
$ git config --list
Further Read
More info here: http://git-scm.com/docs/git-config