Setup GitHub with Automatic Login When You Push Changes

You want to add, commit, and push with git without having to input your username and password. It’s easy to configure. In 5 minutes, you can learn to use git push from your local computer with GitHub in the cloud without typing in your credentials.

There are two methods, ssh and https. The method you use is determined by how you first cloned your repository.

Set Up HTTPS to cache authentication credentials

If you cloned the repository with HTTPS, then use git credential helper to set up the credential cache.

$ git config --global credential.helper 'cache --timeout=100000'
# Set the cache to timeout after 100,000 seconds

HTTPS is the default way to clone a GitHub repository and it’s the recommended way. The timeout value is in seconds. You’ll have to cache the credentials every day.

Set Up ssh for automatic authentication

If you want to use SSH, the first step is to clone with SSH.

Read this article to generate an ssh key and add it to GitHub.

The basic process is:

Paste the text below, substituting in your GitHub email address.

ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
# Creates a new ssh key, using the provided email as a label
Generating public/private rsa key pair.

When you’re prompted to “Enter a file in which to save the key,” press Enter. This accepts the default file location.

Enter a file in which to save the key (/Users/you/.ssh/id_rsa): [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]

Once the key is generated, add it to GitHub.

Test From Command Line

Test to make sure you can use git push without entering your username and password.

$ cat > README.md
test message

$ git add README.md 
$ git commit -a -m 'added test message'
[master bed2406] added test message
 1 file changed, 1 insertion(+)
 create mode 100644 animal/README.md
$ git push
Counting objects: 4, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (4/4), 400 bytes | 0 bytes/s, done.
Total 4 (delta 1), reused 0 (delta 0)
To git@github.com:codetricity/girlcoder.git
   b9a7bf6..bed2406  master -> master

Configure Editor to push to GitHub

In this example, I’m using Atom. Most editors and IDEs support git.

Install the git-plus package.

Once your editor is configured, you can add, commit, push from inside of your editor. Use Ctrl-Shift-H to open up the command palette.

You can also use the drop down menu under Packages.

1 Like