# Create a new empty repo in a folder
# (folder does not have to be empty)
# Clone a remote repo to local location
$ git clone https://github.com/username/repo-name ./local-repo-folder
# Add changes (verbose flag helps!)
# Note that this does not track deleted
# files, use "git add -u -v" below
# Use to track deleted files
# ("git add ." does not do this)
# Stage all changed files, and show which files were staged
# Interactive change-by-change staging
$ git commit -m "Commit message."
## Add remote push location to Github (called "origin") for current repo
# Note that this is the https method, and will require you to
# enter your password on every push.
$ git remote add origin https://github.com/username/repo-name
# Modify an existing push/pull location (in this case origin)
$ git remote set-url origin https://new-url
# Remove remote push location added in previous command (in this case origin)
# Delete local branches that are not present on remote
$ git remote prune origin
$ git remote prune origin --dry-run # Only list them, don't delete
# Push to Github repo added in above command
# Push a specific local branch to a specific remote branch
$ git push origin my_local_branch:my_remote_branch
# To add a lightweight tag to the latest commit
# (in this example I am adding a version number)
# To remove the lightweight tag added above
# Push tags to remote repo location assigned above ("gh")
# (these are not pushed by default, and this does not
# push deleted tags, see below)
# Since I normally always want to push tags at the same
# time as I push commits, I combine the two commands into
$ git push origin; git push origin --tags
# To push deleted tags to a remote location
# (so it deletes the tags at the remote)
$ git push origin :refs/tags/v2.1.0.5
$ git branch -a # Local and remote
# Create a new branch and checkout
$ git checkout -b my-new-branch
# Add a new sub-module to existing repo
# Note that the local install path is relative to the root directory
$ git submodule add https://path.to.remote.repo ./local/install/path
# To revert all uncommitted changes to modified files and delete untracked
# files/directories (useful if you done edits which you no longer wish to
# keep). Calling git reset --hard will print the commit the repo falls back to.
# To print the SHA-1 (long version) of the current commit
# To print changes made in the last two commits (useful to get
# back up to speed on what you're working on)