With Git version 1.7.9 and later
Since Git 1.7.9 (released in late January 2012), there is a neat mechanism in Git to avoid having to type your password all the time for HTTP / HTTPS, called credential helpers. (Thanks to dazonic for pointing out this new feature in the comments below.)
With Git 1.7.9 or later, you can just use one of the following credential helpers:
git config --global credential.helper cache
The credential.helper cache value tells Git to keep your password cached in memory for a particular amount of minutes. The default is 15 minutes, you can set a longer timeout with:
git config --global credential.helper "cache --timeout=3600"
Which sets the cache for 1 hour, or:
git config --global credential.helper "cache --timeout=86400"
For 1 day. You can also store your credentials permanently if so desired, see the other answers below.
GitHub's help also suggests that if you're on Mac OS X and used Homebrew to install Git, you can use the native Mac OS X keystore with:
git config --global credential.helper osxkeychain
For Windows, there is a helper called Git Credential Manager for Windows or wincred in msysgit.
git config --global credential.helper wincred # obsolete
With Git for Windows 2.7.3+ (March 2016):
git config --global credential.helper manager
For Linux, you would use (in 2011) gnome-keyring
(or other keyring implementation such as KWallet).
Nowadays (2020), that would be (on Linux)
Fedora
sudo dnf install git-credential-libsecret
git config --global credential.helper /usr/libexec/git-core/git-credential-libsecret
Ubuntu
sudo apt-get install libsecret-1-0 libsecret-1-dev
cd /usr/share/doc/git/contrib/credential/libsecret
sudo make
git config --global credential.helper /usr/share/doc/git/contrib/credential/libsecret/git-credential-libsecret
With Git versions before 1.7.9
With versions of Git before 1.7.9, this more secure option is not available, and you'll need to change the URL that your origin
remote uses to include the password in this fashion:
https://you:password@github.com/you/example.git
... in other words with :password
after the username and before the @
.
You can set a new URL for your origin
remote with:
git config remote.origin.url https://you:password@github.com/you/example.git
Make sure that you use https
, and you should be aware that if you do this, your GitHub password will be stored in plaintext in your .git
directory, which is obviously undesirable.
With any Git version (well, since version 0.99)
An alternative approach is to put your username and password in your ~/.netrc
file, although, as with keeping the password in the remote URL, this means that your password will be stored on the disk in plain text and is thus less secure and not recommended. However, if you want to take this approach, add the following line to your ~/.netrc
:
machine <hostname> login <username> password <password>
... replacing <hostname>
with the server's hostname, and <username>
and <password>
with your username and password. Also remember to set restrictive file system permissions on that file:
chmod 600 ~/.netrc
Note that on Windows, this file should be called _netrc
, and you may need to define the %HOME% environment variable - for more details see:
Best Answer
1/23/19 UPDATE:
Things have changed quite a bit (for the better) since my last answer. This updated answer will show you how to configure:
In the end, all requests to
example.com
will be re-directed to https://www.example.com (or http:// if you choose NOT to use HTTPS). I always usewww
as my final landing. Why(1,2), is for another discussion.This answer is long but it is not complicated. I was verbose for clarity as the GitHub docs on this topic are not clear or linear.
Step 1: Enable GitHub pages in GitHub settings
GitHub Pages
section. You have two options:master branch
will treat/README.md
as your webindex.html
. Choosingmaster branch /docs folder
will treat/docs/README.md
as your webindex.html
.Your site is ready to be published at
Step 2: Specify custom domain in GitHub settings
Enter your custom domain name here and hit
save
:This is a subtle, but important step.
example.com
, thenwww.example.com
will redirect toexample.com
www.example.com
, thenexample.com
will redirect towww.example.com
.As mentioned before, I recommend always landing at
www
so I enteredwww.example.com
as pictured above.Step 3: Create DNS entries
In your DNS provider's web console, create four
A
records and oneCNAME
.A
Records for@
(aka root apex):Some DNS providers will have you specify
@
, others (like AWS Route 53) you will leave the sub-domain blank to indicate@
. In either case, these are theA
records to create:Check the Github docs to confirm these are the most up-to-date IPs.
CNAME
record to point www.example.com toYOUR-GITHUB-USERNAME.github.io
.This is the most confusing part.
Note the
YOUR-GITHUB-USERNAME
NOT the GitHub repo name! The value ofYOUR-GITHUB-USERNAME
is determined by this chart.For a User pages site (most likely what you are),
CNAME
entry will beusername.github.io
, ex:For a Organization pages site,
CNAME
entry will beorgname.github.io
, ex:Step 5: Confirm DNS entries
Confirm your
A
records by runningdig +noall +answer example.com
. It should return the four185.x.x.x
IP addresses you entered.Confirm your
CNAME
record by runningdig www.example.com +nostats +nocomments +nocmd
. It should return aCNAME YOUR-GITHUB-USERNAME.github.io
It may take an hour or so for these DNS entries to resolve/propagate. Once they do, open up your browser to
http://example.com
and it should re-direct tohttp://www.example.com
Step 6: SSL (HTTPS) Configuration. Optional, but highly recommended
After you have the custom domain working, go back to the repo settings. If you already have the settings page open, hard refresh the page.
If there is a message under the
Enforce HTTPS
checkbox, stating that it is still processing you will need to wait. You may also need to hit thesave
button in theCustom domain
section to kick off theEnforce HTTPS
processing.Once processing is completed, it should look like this:
Just click on the
Enforce HTTPS
checkbox, and point your browser tohttps://example.com
. It should re-direct and openhttps://www.example.com
THATS IT!
GitHub will automatically keep your HTTPS cert up-to-date AND should handle the apex to
www
redirect over HTTPS.Hope this helps!!