GitHub

From Omnia
Jump to navigation Jump to search

GitHub

GitHub · Build software better, together. - https://github.com/

"GitHub · Build software better, together."

Global setup:

Download and install Git
 git config --global user.name "Your Name"
 git config --global user.email kiloforce@k.ttak.org
 Add your public key

Next steps:

 mkdir test
 cd test
 git init
 touch README
 git add README
 git commit -m 'first commit'
 git remote add origin git@github.com:kiloforce/test.git
 git push origin master
     

Existing Git Repo?

 cd existing_git_repo
 git remote add origin git@github.com:kiloforce/test.git
 git push origin master

Caching Password

authentication - Git push requires username and password - Stack Overflow - http://stackoverflow.com/questions/6565357/git-push-requires-username-and-password

The following command will save your password in memory for sometime. (For git 1.7.10 or newer.)

# Set git to use the credential memory cache
$ git config --global credential.helper cache
# Set the cache to timeout after 1 hour (setting is in seconds)
$ git config --global credential.helper 'cache --timeout=3600'

Git

See Git

GitHub Flavored Markdown

See GitHub/GitHub Flavored Markdown

GitHub Gist

Gist is a simple way to share snippets and pastes with others. All gists are Git repositories, so they are automatically versioned, forkable and usable from Git.

https://gist.github.com/

GitHub Pages

"Websites for you and your projects, hosted directly from your GitHub repository."

GitHub Pages - https://pages.github.com/

Supports static HTML content

Warning: GitHub Pages sites are publicly available on the internet, even if their repositories are private. If you have sensitive data in your Page repository, you may want to remove it before publishing.

User Pages

Only one set of User/Organization pages are available per account. (Although multiple project pages are allowed)

User/Organization Site: (must live in master branch)

  1. On GitHub and create a new repository named username.github.io (where username is your username (or organization name) on GitHub).
    • Note: If the first part of the repository doesn’t exactly match your username, it won’t work, so make sure to get it right.
  2. Clone repo
  3. Add index.html
    • cd username.github.io ; echo "Hello World" > index.html
  4. Push it
    • git add --all ; git commit -m "Initial commit" ; git push -u origin master
  5. Browse to new site: (may have to wait a few minutes for the pages to be generated by GitHub)

Project Pages

Project pages work similar to User Pages, but each project can have their own set of Project Pages.

To setup Project Pages, simply create a branch called gh-pages

# Creates our branch, without any parents (it's an orphan!)
git checkout --orphan gh-pages

# Remove all files from the old working tree
git rm -rf .
echo "My Page" > index.html
git add index.html
git commit -a -m "First pages commit"
git push origin gh-pages

Browse to: http://<username>.github.io/<projectname>

Custom URL

Setup a custom URL [1]

--- DNS ---

Create a CNAME on your sub domain name to point to username.github.io. [2] [3]

If pointing an apex domain level, point A record to the following IP addresses: [4]

   192.30.252.153
   192.30.252.154

If your DNS provider supports it, you can also have your apex domain name use an Alias (ANAME) record to point to username.github.io.

If you also create a www subdomain CNAME, GitHub will also respect this too. [5]

--- GitHub CNAME file ---

CNAME file: [6]

If you're using a custom domain to redirect your GitHub Pages site, you must create and commit a CNAME file to your GitHub Pages repository that contains the custom domain.

In the "Branches" menu, switch to your repository's Pages branch:

  • For User and Organization Pages sites, the Pages branch is master.
  • For Project Pages sites, the Pages branch is gh-pages.

In the new file, add a single line that specifies the bare subdomain for your custom domain. For example, use blog.example.com, not https://blog.example.com. Note that there can only be one domain in the CNAME file.

Verify the change by looking under the project's settings, under "GitHub Pages".

Note, the Project Pages site inherits the domain set for its owner's User Pages site, but can be overridden with it's own Custom URL.

Automatic Page Generation

Automatic Page Generation [7] - You can use GitHub's Automatic Page Generator to quickly create a website for a project, user, or organization.

  1. Go to the repository's settings page.
  2. Click the Automatic Page Generator button.

GitHub Pages Disk Quota

"Rule of thumb: 1GB per repository, 100MB per file" [8]

Sync Forked Repo

Configure remote for fork: [9]

git remote -v
git remote add upstream https://github.com/ORIGINAL_OWNER

Sync fork: [10]

git fetch upstream
git checkout master
git merge upstream/master

Fix Author Email

#!/bin/sh

git filter-branch -f --env-filter '
OLD_EMAIL="your-old-email@example.com"
CORRECT_NAME="Your Correct Name"
CORRECT_EMAIL="your-correct-email@example.com"
if [ "$GIT_COMMITTER_EMAIL" = "$OLD_EMAIL" ]
then
    export GIT_COMMITTER_NAME="$CORRECT_NAME"
    export GIT_COMMITTER_EMAIL="$CORRECT_EMAIL"
fi
if [ "$GIT_AUTHOR_EMAIL" = "$OLD_EMAIL" ]
then
    export GIT_AUTHOR_NAME="$CORRECT_NAME"
    export GIT_AUTHOR_EMAIL="$CORRECT_EMAIL"
fi
' --tag-name-filter cat -- --branches --tags
  1. Modify and Run script
  2. git push --force --tags origin 'refs/heads/*'

Changing author info - User Documentation - https://help.github.com/articles/changing-author-info/

Issues

https authentication

Error:

$ git push
error: The requested URL returned error: 403 Forbidden while accessing https://github.com/oeey/ksmtp/info/refs

fatal: HTTP request failed

Solutions:

  • Use SSH keys and git:// protocol
  • Add username:password to origin url in .git/config:
[remote "origin"]
        fetch = +refs/heads/*:refs/remotes/origin/*
        url = https://[GITUSER]:[GITPASSWORD]@github.com/oeey/ksmtp

keywords