Created
August 20, 2020 23:49
-
-
Save cweedall/aaeaa04c3421d905a41665c9a042de0c to your computer and use it in GitHub Desktop.
Cheatsheet for configuring git locally and creating/updating repositories
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Install hub - the API for github and git | |
sudo apt-get install hub | |
### | |
### See link for details on `hub` API: | |
### https://hub.github.com/ | |
### | |
# Prefer the HTTPS protocol for git operations: instead of git: or ssh:: | |
# This will affect `clone`, `fork`, `remote add` and other `hub` commands that expand shorthand references to GitHub repo URLs. | |
git config --global hub.protocol https | |
# Set username and email address | |
git config --global user.name "YOUR_USERNAME" | |
################################################# | |
#### If email privacy is turned on in Github #### | |
#### SEE: https://stackoverflow.com/a/51097104/7363740 | |
################################################# | |
# Setting your email address for every repository on your computer | |
git config --global user.email "{ID}+{username}@users.noreply.github.com" | |
# Setting your email address for a single repository | |
git config user.email "{ID}+{username}@users.noreply.github.com" | |
# Reset the author information on your last commit (if necessary) | |
git commit --amend --reset-author | |
################################################# | |
################################################# | |
### Remember creditials for future use | |
### (especially useful when using 2FA and have a personal access token) | |
### SEE: https://docs.github.com/en/github/using-git/caching-your-github-credentials-in-git | |
################################################# | |
# (easier, but less secure) | |
#git config credential.helper store | |
# or | |
git config --global credential.helper cache | |
# (only stored temporarily, but more secure) | |
#git config credential.helper 'cache --timeout=3600' | |
# or | |
git config --global credential.helper 'cache --timeout=3600' | |
################################################# | |
################################################# | |
### Create a repo to host a new project on GitHub | |
################################################# | |
# Get files ready - e.g. make an empty README.md file | |
touch README.md | |
# Initialize a new git project (see .git folder) | |
git init | |
# Add your file(s) to be updated in repository | |
git add . | |
#OR - if only select files | |
git add FILENAME | |
# Commit changes for updating the repository | |
git commit -m "First commit" | |
# Creates a new GitHub repository with the name of the current directory | |
hub create | |
# Push the changes to github -- HEAD is the same name as current directory | |
git push -u origin HEAD | |
################################################# | |
################################################# | |
### Push an existing repo's changes to GitHub | |
################################################# | |
# MAKE YOUR CHANGES FIRST | |
# Add your file(s) to be updated in repository | |
git add . | |
#OR - if only select files | |
git add FILENAME | |
# Commit changes for updating the repository | |
git commit -m "COMMIT DESCRIPTION" | |
# Push the changes to github -- HEAD is the same name as current directory | |
git push -u origin HEAD | |
################################################# | |
################################################# | |
### Commit mistake??? Remove files from git staging area | |
################################################# | |
git reset HEAD -- . | |
# or | |
git reset HEAD -- /path/to/filename | |
# or (if in same directory as file) | |
git reset HEAD -- filename | |
################################################# | |
################################################# | |
### !!!WARNING!!! | |
### Delete an existing repo from GitHub | |
### !!!WARNING!!! | |
### See: | |
### https://hub.github.com/hub-delete.1.html | |
################################################# | |
# If run from any location | |
hub delete REPO_NAME | |
# or | |
hub delete USERNAME/REPO_NAME | |
# If run from repo's directory | |
hub delete `basename $PWD` | |
### NOTE: If you encounter the error below::: | |
# Please edit the token used for hub at https://github.com/settings/tokens | |
# and verify that the `delete_repo` scope is enabled. | |
# Error deleting repository: Forbidden (HTTP 403) | |
# Must have admin rights to Repository. | |
### THEN: you need to make sure your account and/or personal access token has permissions | |
### to delete repositories. | |
### Go to Settings->Developer Settings->Personal access tokens->(YOUR TOKEN)->select delete_repo - Delete repositories->Update token | |
################################################# |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment