Skip to content

Instantly share code, notes, and snippets.

@graphicsminded
Last active April 21, 2016 03:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save graphicsminded/292f4217fa3c275597586a060ec6a759 to your computer and use it in GitHub Desktop.
Save graphicsminded/292f4217fa3c275597586a060ec6a759 to your computer and use it in GitHub Desktop.
Git Command Cheat Sheet

Git Commands in a Project Workflow

USERNAME is you
MYPROJECT is the name of your project

Create a MYPROJECT repository on GitHub but don't include ANY files (not even README.md or .gitignore). Then in a local directory create your local repository from the commandline.

Create a Project

mkdir MYPROJECT
cd MYPROJECT/
git init

Blank Slate Initial Commit

git commit --allow-empty -m "Initial commit"
git tag -a v0.0.0 -m "Initial commit"

Connect Local Repository to GitHub Origin Repository

git remote add origin https://github.com/USERNAME/MYPROJECT.git
(might ask for username and password)
git push -u --follow-tags origin master

Add and Modify Files

Add and modify files to the workspace. Add the files to the index:

git add .

Commit your Changes

Commit your changes from index to local repository

git commit -m "Commit some changes"

Tag your Commit

Get the SHA1 of the last commit and copy the beginning part its hash line.

git log

Produces: c15c9a5076803b497156bcf0b39cd5422728b4bf

Create a tag of v0.1.0 for commit that starts with c15c9a5

git tag v0.1.0 c15c9a5

Push Your Commit

From remote local repository Master branch to origin GitHub Master branch

git push origin master

Push Your Tags

Git does not push tags by default. You will have to explicitly push tags to a shared server after you have created them. To push a single tag to origin run:

git push origin [tagname]

To push all of your tags not on origin server run:

git push origin --tags
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment