Skip to content

Instantly share code, notes, and snippets.

@markmichon
Created May 23, 2012 20:02
Show Gist options
  • Save markmichon/2777431 to your computer and use it in GitHub Desktop.
Save markmichon/2777431 to your computer and use it in GitHub Desktop.
Useful Github Commands
//Git Commands
# NOTES: Lines starting with // or # are comments and should not be typed into terminal. Please be careful of your spelling, spacing, and case before initiating a command in terminal.
//Standards Commands to push to github (in order)
git add .
# adds all files and folders that contain files to be commited
git status
# shows what changes are going to be commited
git commit -m 'Some descriptive commit message'
# commits all added items to the staging area with the included commit message
git push origin master
# pushes or 'syncs' your local git repo, origin, with the github.com master repo
//Standard Commands to copy origin to gh-pages
git checkout gh-pages
# Change to the gh-pages branch
git merge master
# bring gh-pages up to date with master
git push origin gh-pages
# push the changes to the server's gh-pages branch
git checkout master
# return to the master branch
//Alternate way to copy master to gh-pages
git checkout gh-pages
# Change to the gh-pages branch
git rebase master
# bring gh-pages up to date with master (The different here is that rebase is copying all commits from master and overriding them on gh-pages)
git push origin gh-pages
# push the changes to the server's gh-pages branch
git checkout master
# return to the master branch
//Misc Commands
git branch gh-pages // creates a gh-pages branch locally
Setting up a New Repo
------------------------
cd /path/to/folder/of/your/files/
# change terminal's directory to that of your local repository folder
git init
# initialize git. This creates a hidden .git folder in the current location
git add .
# adds all files and folders in the current directory to the commit list
git commit -m 'first commit of new files'
# commits all added files and includes the desired commit message
git remote add origin git@github.com:YOURUSERNAME/THENAMEOFYOURREPO.git
# links your local repo with the desired github repo. Replace this URL with the one given to you on your repo page. If done correctly you will never need to do this again for the current folder.
git push -u origin master
# Pushes the local files to the server
//Changing the remote url: this is used when you need to change the connection between a local repo and the server.
git remote -v
# View existing remotes
# origin https://github.com/user/repo.git (fetch)
# origin https://github.com/user/repo.git (push)
git remote set-url origin https://github.com/user/repo2.git
# Change the 'origin' remote's URL
git remote -v
# Verify new remote URL
# origin https://github.com/user/repo2.git (fetch)
# origin https://github.com/user/repo2.git (push)
@jamesmichiemo
Copy link

Thanks Mark. I have an easier time using this cheat sheet vs playing with the github gui.

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