Skip to content

Instantly share code, notes, and snippets.

@loujaybee
Last active September 22, 2016 01:58
Show Gist options
  • Save loujaybee/3ce6fde7f193a3b061462737376b77c3 to your computer and use it in GitHub Desktop.
Save loujaybee/3ce6fde7f193a3b061462737376b77c3 to your computer and use it in GitHub Desktop.
Git basics

Gotcha's / Things to watch out for

  • You're creating a new branch, all changes on this branch are different from changes on master
  • You can resolve this in a number of ways, for now just stay and work on the gh-pages branch for ease
  • It is generally good practice to keep 'master' as the source of truth, that's why it's master so we will cover merging things back to master eventually

Git basics: Setting up a github pages

Step 1: Create the repo online

Step 2: git clone your-url

git clone https://your-url

  • This assumes you have your authentication setup
  • When you've created the new repo, run this command
  • The local folder, setup and synced with your github one

Step 3: Create a file

touch readme.md

  • Creates you a new file
  • The touch command says is basically saying "touch this file" which if the file doesn't exist, it creates a new one, if it does, it updates the update date

Step 4: Add your files that are changed

git add readme.md

  • This is required, you must tell git what pages you want to commit
  • This process is called "staging"
  • This will add the new read me file that you just made
  • If you're feeling lazy use git add --all
    • However remember that this is usually not recommeneded
    • Try to explicitly add all of your files, this prevents commiting mistakes
    • Ideally you would step through and add each 'chunk' of code but that's a more advanced technique done through git add -p which we can cover later!

Step 5: Commit your files

git commit -m "Your commit message goes here"

  • Commit it with a message
  • The message will then appear in git hub
  • Try to make it really useful and descriptive so when you reread your commits you know what the changes were that you were trying to make

Step 6: Push back to github.com

git push

  • That sets up master with a readme file
  • Pushes your local branch back up to the 'remote' (basically just syncs back up with github.com) so your repo shows your code, and so github pages shows the code you just pushed

Step 7: Change to gh-pages branch

git checkout -b gh-pages

  • git checkout on its own will swap to a new branch
  • by adding -b you're saying "make me a new branch and swap to it"
  • Checking out a new branch
  • Note: create a new branch based off the current one and then swap to that branch

# Step 8:

git push

  • Push to github!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment