{"id":13303482,"url":"https://github.com/discontented/github-notes","last_synced_at":"2025-03-10T13:31:14.599Z","repository":{"id":131361843,"uuid":"117988489","full_name":"discontented/github-notes","owner":"discontented","description":null,"archived":false,"fork":false,"pushed_at":"2018-06-18T03:09:38.000Z","size":1431,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-07-29T18:26:28.913Z","etag":null,"topics":["git-hooks","github","github-desktop","ssh-key"],"latest_commit_sha":null,"homepage":"http://josh-corneille.com/github-notes/","language":"CSS","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/discontented.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-01-18T13:45:58.000Z","updated_at":"2024-07-29T18:26:37.414Z","dependencies_parsed_at":null,"dependency_job_id":"a39854f6-8e45-4cb6-9de3-2aea6d910643","html_url":"https://github.com/discontented/github-notes","commit_stats":null,"previous_names":["discontented/github-notes"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/discontented%2Fgithub-notes","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/discontented%2Fgithub-notes/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/discontented%2Fgithub-notes/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/discontented%2Fgithub-notes/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/discontented","download_url":"https://codeload.github.com/discontented/github-notes/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242859531,"owners_count":20196961,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["git-hooks","github","github-desktop","ssh-key"],"created_at":"2024-07-29T17:50:55.632Z","updated_at":"2025-03-10T13:31:14.231Z","avatar_url":"https://github.com/discontented.png","language":"CSS","funding_links":[],"categories":[],"sub_categories":[],"readme":"# github-notes\n\nGit is a software that allows you to keep track of changes made to a project over time. Git works by recording the changes you make to a project, storing those changes, then allowing you to reference them as needed.\n\n- [github-notes](#github-notes)\n    - [Git Workflow](#git-workflow)\n    - [Git Commands](#git-commands)\n        - [Initializing](#initializing)\n        - [Status](#status)\n        - [Adding to the Staging Area](#adding-to-the-staging-area)\n        - [Check Differences](#check-differences)\n        - [Check Status](#check-status)\n        - [Pushing](#pushing)\n        - [Pulling](#pulling)\n        - [Removing](#removing)\n            - [Discard Local Changes](#discard-local-changes)\n    - [View Commit History](#view-commit-history)\n        - [`git log` Flags](#git-log-flags)\n    - [Undo Functions](#undo-functions)\n    - [Branches](#branches)\n        - [Check Differences Between Branches](#check-differences-between-branches)\n    - [Using Git with Github](#using-git-with-github)\n    - [Git URLs](#git-urls)\n        - [Generating an SSH Key](#generating-an-ssh-key)\n        - [Add SSH to GitHub Account](#add-ssh-to-github-account)\n        - [Copy SSH Key Remotely](#copy-ssh-key-remotely)\n        - [Deploy Keys with AWS](#deploy-keys-with-aws)\n    - [Using GitHub Desktop](#using-github-desktop)\n    - [Git Hooks](#git-hooks)\n        - [Client-side Hooks](#client-side-hooks)\n        - [Server-Side Hooks](#server-side-hooks)\n        - [Webhooks](#webhooks)\n        - [Installation](#installation)\n    - [Common Errors](#common-errors)\n        - [Could not resolve hostname](#could-not-resolve-hostname)\n        - [Continually prompting for username](#continually-prompting-for-username)\n        - [Repository or Branch DNE](#repository-or-branch-dne)\n        - [Permission Denied (publickey)](#permission-denied-publickey)\n        - [Force Git Pull](#force-git-pull)\n    - [Resources](#resources)\n\n## Git Workflow\n\n1. A Working Directory: where you'll be doing all the work: creating, editing, deleting and organizing files\n2. A Staging Area: where you'll list changes you make to the working directory\n    * \"Tracked files\"\n3. A Repository: where Git permanently stores those changes as different versions of the project\n    * Changes are saved as a commit\n\n## Git Commands\n\n### Initializing\n\n`git init`\n\n* Initializes an empty Git repository in the current working directory.\n* Sets up the tools Git needs to begin tracking changes on the current project.\n* Creates a hidden folder /.git/ in the directory where git operates.\n\n### Status\n\n`git status`\n\n* Lists any changes of the contents in the working directory.\n* Untracked files will be displayed in red\n  * Untracked files do not have any changes stored.\n* Green files show changes to a file that need to be committed.\n\n### Adding to the Staging Area\n`git add \u003cfile\u003e`\n\n* Adds the specified file to the staging area.\n* Specified file is now tracked if it was untracked.\n\n```bash\ngit remote add \u003cremote name\u003e \u003cURL\u003e\ngit remote add origin https://github.com/user/repo.git\n```\n* \u003cURL\u003e is the destination of a remote repository.\n* The name is anything you give it.\n* This adds your local repo to the remote one.\n\n`git add .`\n* Shortcut method that will add all files in the current directory except for the ignored files.\n  * Ignored files are stored within .gitignore/\n\n### Check Differences\n* You can check the differences between tracked local files and files in the repo or staging area.\n\n`git diff \u003cfile\u003e`\n\n* Displays changes to a tracked file between the local file and those added to the staging area\n* Additions to the file are preceded by a + and in green\n* Any missing lines are preceded by a – and in red\n* The same lines are in white\n\n`git diff HEAD`\n* The most recent change to the last file you committed.\n\n`git diff {branch}@{1} {branch}`\n\n* Displays differences between previous branch version and current version.\n  * The previous version is one which was last pushed to repo.\n\n### Check Status\n\n`git status`\n* Lists the current branch and any differences\n* When it says 'up-to-date' it means up-to-date with the branch that the current branch tracks.\n  * Usually this is the local reference\n  * Not \"up-to-date with the latest live status of the upstream.\n\n`git checkout -b \u003cbranch-name\u003e`\n*\tCreate a new branch locally.\n\n### Pushing\n`git commit -a`\n* Automatically stage every file that is already tracked.\n  * Skips `git add` step.\n\n`git push -u \u003corigin\u003e \u003cbranch-name\u003e`\n*\tTo push a local new branch to the remote\n*\t-u stands for –set-upstream\n    * tells git to remember all of the commands so that \u003cgit push\u003e will execute the same command as an alias now.\n\n### Pulling\n`git pull \u003corigin\u003e \u003cbranchName\u003e`\n* Returns any changes that have been made to the files under the folder name.\n* Brings the local branch up-to-date with the remote branch.\n* Combines `git fetch` and `git merge`\n* \n`git commit`\n*\tAny files added to the unstaged area which have been changed can be committed to the repository.\n\n`git fetch`\n* A local repo won't reflect changes that have been made on the remote repo, so it must be updated first before changes are made.\n* `fetch` gets up to date with the commits from the remote repo\n  * This does not update the local files so it will not change your local working copy.\n\n`git merge`\n* merge moves those commits to the local branch\n\n### Removing\n`git rm \u003cfile\u003e`\n* Removes the file from the working directory and from tracked files.\n* If you remove the file from the working directory\n\n#### Discard Local Changes\n* For all locally staged files\n`git reset --hard`\n* For a single file\n`git checkout \u003cfilename\u003e`\n\n## View Commit History\n\n`git log`\n* Lists commits made in a repository in reverse chronological order.\n* Commit history includes:\n    * SHA-1 checksum\n    * Author's name and email\n    * Date written\n    * Commit message\n\n### `git log` Flags\n`-p`\n* Shows difference introduced from each commit.\n* If following the `-p` flag by a number, then it will limit the output to the max number of commits.\n\n`--since=\u003cn\u003e.weeks`\n* Shows commits occuring within the last n weeks.\n\n`--S\u003cstring\u003e`\n* Displays commits that changed the specified string.\n\n    `git log --Sfunction_name`\n    * Displays all commits where the function_name was added or removed.\n\n`--author`\n* Displays commits by a specified author.\n\n\n## Undo Functions\n`git commit -amend`\n* If a commit message is messed up or files were forgotten to be restaged, you can redo the commit message.\n\n## Branches\n`git branch`\n* Lists all branches of repository\n* Current branch is preceded by an asterisk\n\n### Check Differences Between Branches\n\n`git fetch`\n*\tRun git fetch first to make sure the local branch is updated.\n\n`git branch`\n*\tList all available branches\n\n`git diff (local-branch) (remote-branch)`\n*\tCompare the differences between each branch.\n*\tThe first listed branch is considered branch A and the second branch is branch B\n*\tAny changes that are within A that are not in B are preceded by a – and listed in red.\n*\tAny changes within B but not in A are preceded with a + and listed in green.\n\n## Using Git with Github\n1.\tInitialize the local directory as a git directory\n`git init`\n2.\tAdd all files currently in the directory to be staged for commit\n`git add .`\n3.\tCommit the files you've staged\n`git commit -m \"First commit\"`\n4.\tCreate the new repository on github\n5.\tGet the github repository's URL from the quick setup page\n6.\tAdd the url for the remote repository\n`git remote add origin \u003cURL\u003e`\n`git remote -v`\n7.\tPush the changes to master branch\n`git push origin master`\n\n## Git URLs\n\n*\tGit provides https or SSH to download and upload.\n\n### Generating an SSH Key\n\n* The command `ssh-keygen` will generate a private and public OpenSSH key with the default name `id_rsa`\n    * The key will be located at `~/.ssh/`\n        * `~/.ssh` is shorthand for the current user's home directory.\n        * The location of the ssh key will be stored in `/home/\u003cusername\u003e/.ssh/`\n\n* Github email address is address you use to login `ssh-keygen -t rsa -b 4096 -C “email@address.com”`\n    * `-t` specifies the type of key.\n    * `-b` specifies the number of bits in the key to create.\n        * default is 2048 bits\n    * `-C` adds a comment\n        * The comment is only serving as a label and not functionality.  It can be generated without it, such as an SSH key for a shared repo on a shared server.\n* An SSH key will be generated in a file.\n* May add a passphrase for added security.\n* ssh-agent manages your SSH keys.\n    * the key must be added to ssh-agent to use\n* Generate an agent id:\n`eval $(ssh-agent -s)`\n* Add the private key to the ssh-agent\n`ssh-add ~/.ssh/\u003cprivate_key_name\u003e`\n\n### Add SSH to GitHub Account\n\n* Adding an SSH key to your account will allow you to push/pull to all of your GitHub repos from the server where the SSH key exists since it is identifying the server as you.\n    * If this server will be accessible by others, consider using a [deploy key](#deploy-keys) for a specific repo.\n* Check for existing keys `ls -al ~/.ssh`\n    * will have a .pub extension for the public key\n    * The private key will be the same name without an extension.\n\n* Copy the SSH key to your clipboard `clip \u003c ~/.ssh/id_rsa.pub`\n    * This will only work if you are working on a local terminal.  If you are using PuTTY or another SSH client, then use [copying SSH remotely](#copy-ssh-key-remotely)\n* Go to your user settings on github.\n* Click on SSH and GPG keys.\n* The “Title” field is only descriptive.\n    * Name it after the computer that is accessing github\n* “Key” field\n    * Paste in the SSH key that was generated through ssh-keygen\n\n### Copy SSH Key Remotely\n\n* If using PuTTY or any other remote SSH client, print the key to the shell:\n\n`ssh-keygen -y -f \u003ckey location\u003e`\n\n* `-y` outputs the public key\n* `-f` input file\n* `\u003ckey location\u003e`\n    * Usually located at ~/.ssh/id_rsa\n\n### Deploy Keys with AWS\n\n1. Log into root user `sudo su`\n2. Run `ssh-keygen` to generate a key.\n    1. If a key already exists you can check with `ls -al ~/.ssh`\n    2. Leave blank for name and passphrase.  The name will default to id_rsa.\n    3. If wanting to use an SSH agent:\n        1. Generate an agent id: `eval $(ssh-agent -s)`\n        2. Add the private key to the ssh-agent `ssh-add ~/.ssh/\u003cprivate_key_name\u003e`\n3. Print the `ssh-keygen -y -f ~/.ssh/id_rsa` and copy.\n    1. If you highlight the text with RMB in PuTTY it will automatically copy.\n4. Paste this key into the repo's deploy keys.\n5. Test connection to github `ssh -T git@github.com`\n    1. If successful what should be displayed is\n    ```bash\n    Hi {username/repo} You\\'ve successfully authenticated, but GitHub does not provide shell access.\n    ```\n6. Try interacting with the repo!\n    1. clone\n    2. push\n    3. pull\n\n## Using GitHub Desktop\n\nTo clone a repository from GitHub onto your local machine:\n![Cloning a Repository](images/clone-repo.gif)\n\n* After code has been completed in your local environment, commit to the GitHub repo by adding a message and pushing to the repo.\n* This can also be done through a CLI with:\n\n```bash\ngit add \u003cfile\u003e\ngit commit -m \"\u003cmessage\u003e\"\ngit push\n```\n\n![Commiting and Pushing](images/commit-push.gif)\n\n* GitHub desktop downloads and updates to the folder you specified when cloning.\n    * If there are multiple branches, the folder only contains contents of the current branch.\n        * Contents of branches do not simultaneously exist in the same folder.\n    * You must switch to a different branch through GitHub desktop or the CLI to load those branches.\n* GitHub Desktop can open files to be edited in your favorite IDE:\n![Open in IDE](images/open-editor.gif)\n\n## Git Hooks\n\n* Fires off custom scripts when events occur in the repo.\n* Can reside in either local or server-side repositories.\n* Hooks are stored in the .git/hooks/ folder of a repo\n* The scripts in the /hooks/ folder must be executable and first line must be a shebang magic number that calls the correct script interpreter.\n* All default hooks have the extension `.sample`\n    * Must remove `.sample` for the script to execute\n\n### Client-side Hooks\n\n* Triggered by committing or merging\n\n### Server-Side Hooks\n\n* Receive pushed commits\n* Scripts run before and after pushes to the server.\n* When there is a push from a client:\n    * `pre-receive`\n        * Makes sure none of the updated references are non-fast-forwards.\n        * If pusher is trying to push to multiple branches, runs only once.\n    * `update`\n        * Run once for each branch the pusher is trying to update.\n        * If pusher trying to push to multiple branches, runs once per branch they're pushing to.\n    * `post-receive`\n        * Can be used to update other services or notify users.\n            * e-mail\n            * notifying a CI server\n            * update ticket-tracking system\n\n### Webhooks\n\n### Installation\n\n* Stored in hooks subdirectory of Git project.\n    * Usually `.git/hooks`\n\n## Common Errors\n\n### Could not resolve hostname\n\n```bash\ngit push -u \u003corigin\u003e \u003cbranch\u003e\nssh: Could not resolve hostname https: Name or service not known.\n```\n\n* The hostname stored in origin is most likely wrong.\n* Double check it with: `git remote -v` compared to the link provided at the GitHub repo.\n* To change the url: `git remote set-url \u003corigin\u003e \u003cURL\u003e`\n\n### Continually prompting for username\n\n* The hostname stored in origin is most likely wrong.\n* Double check it with: `git remote -v` compared to the link provided at the GitHub repo.\n* To change the url: `git remote set-url \u003corigin\u003e \u003cURL\u003e`\n\n* If the remote url is correct and you are using the HTTPS method, then try storing credentials with git:\n```bash\n$ git config credential.helper store\n$ git push http://example.com/repo.git\nUsername: \u003ctype your username\u003e\nPassword: \u003ctype your password\u003e\n```\n\n`git config credential.https://example.com.username myusername`\n\n* `git help credentials` provides the manual page for how git stores credientials.\n\n### Repository or Branch DNE\n\n```bash\ngit push -u \u003corigin\u003e \u003cbranch\u003e\nremote: Repository not found\n```\n\n```bash\ngit checkout\nyou are on a branch yet to be born\n```\n\n* Make sure the repository has been initialized locally\n* Make sure the repository exists on github.\n* Make sure the local repository knows of the remote repository.\n    * Double check it with: `git remote -v`\n        * If it does not know of the remote repository, get the repository’s address from github.\n\n`git remote add \u003corigin-name\u003e \u003curl\u003e`\n*\tAdd the contents of the folder to be staged: `git add .`\n*\tCommit the file: `git commit -m “commit message”`\n*\tDouble check you are on the same branch you are trying to push to `git status`\n*\tIf you are not, check the local branches: `git branch`\n*\tIf it does not exist locally `git checkout -b \u003cbranch-name\u003e`\n*\tPush the file `git push -u \u003corigin-name\u003e \u003cbranch-name\u003e`\n\n\n### Permission Denied (publickey)\n```bash\nPermission denied (publickey).\nfatal: Could not read from remote repository.\n\nPlease make sure you have the correct access rights\nand the repository exists.\n```\n\n* Run `ssh -vT git@github.com`\n* Start ssh-agent\n`ssh-agent -s`\n* Check that a public key is loaded into ssh-agent\n`ssh-add -l`\n\n### Force Git Pull\n```bash\ngit fetch -all\ngit reset --hard origin/\u003cbranch_name\u003e\n```\n\n## Resources\n\n[Git Hooks](https://git-scm.com/book/gr/v2/Customizing-Git-Git-Hooks)\n\n[Git Hooks Tutorial](https://www.atlassian.com/git/tutorials/git-hooks)\n\n[Webhooks - GitHub](https://developer.github.com/webhooks/)\n\n[Git Hook Tutorial](https://www.digitalocean.com/community/tutorials/how-to-use-git-hooks-to-automate-development-and-deployment-tasks)\n\n[new keys for ssh github](https://help.github.com/articles/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent/)\n\n[Setting up git with SSH](https://gist.github.com/stormpython/9517102)\n\n[Deploy Keys](https://developer.github.com/v3/guides/managing-deploy-keys/)\n\n[Permission Denied Error](https://help.github.com/articles/error-permission-denied-publickey/)\n\n[git diff master](https://stackoverflow.com/questions/1362952/detail-change-after-git-pull)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdiscontented%2Fgithub-notes","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdiscontented%2Fgithub-notes","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdiscontented%2Fgithub-notes/lists"}