{"id":20271724,"url":"https://github.com/rodneyshag/git","last_synced_at":"2026-03-08T15:31:24.168Z","repository":{"id":123421735,"uuid":"211985718","full_name":"RodneyShag/Git","owner":"RodneyShag","description":"Git - basic commands","archived":false,"fork":false,"pushed_at":"2021-06-08T02:39:56.000Z","size":19,"stargazers_count":16,"open_issues_count":0,"forks_count":20,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-14T05:49:42.500Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":null,"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/RodneyShag.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":"2019-10-01T00:47:55.000Z","updated_at":"2023-05-03T13:05:27.000Z","dependencies_parsed_at":null,"dependency_job_id":"33b6e15f-519b-4ec0-9ff8-b8daa129d3c3","html_url":"https://github.com/RodneyShag/Git","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RodneyShag%2FGit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RodneyShag%2FGit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RodneyShag%2FGit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RodneyShag%2FGit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/RodneyShag","download_url":"https://codeload.github.com/RodneyShag/Git/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241758964,"owners_count":20015251,"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":[],"created_at":"2024-11-14T12:39:12.386Z","updated_at":"2026-03-08T15:31:19.149Z","avatar_url":"https://github.com/RodneyShag.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n    \u003ca href=\"http://files.zeroturnaround.com/pdf/zt_git_cheat_sheet.pdf\"\u003e\n    \u003cimg src=\"images/git_logo.png\"\u003e\n    \u003cbr\u003eCheatsheet\n    \u003c/a\u003e\n\u003c/p\u003e\n\n- [Common Commands](#common-commands)\n- [More commands](#more-commands)\n- [Create repository](#create-repository)\n- [Clone repository](#clone-repository)\n- [Submit changes](#submit-changes)\n- [Rebase](#rebase)\n- [Revert changes](#revert-changes)\n- [Stashing](#stashing)\n- [Merge branch](#merge-branch)\n- [Troubleshoot](#troubleshoot)\n\n## Common Commands\n\nAll commands should be run without the \u003c\u003e brackets\n\n- `git log` shows commit ids. The latest commit is at the top.\n    - `git log -p` - lists the changed files\n- `git checkout -b develop` checks out a new branch called \"develop\"\n    - `git checkout init_devices` switches branch to _init_devices_\n    - `git checkout \u003ccommit_number\u003e` goes to a specific commit\n    - `git checkout -b 1234 origin/mainline` checks out a new branch called \"1234\", that \"tracks\" origin/mainline, meaning \"local branch has its upstream set to a remote branch\" ([Reference](https://stackoverflow.com/questions/10002239/difference-between-git-checkout-track-origin-branch-and-git-checkout-b-branch)). Here's more info: [Tracking branches](https://stackoverflow.com/questions/4693588/what-is-a-tracking-branch)\n- `git status` lists new or modified files not yet committed\n- `git diff \u003ccommit_number\u003e` compares current code to any commit\n- `git add *` adds all files to \"Staging\". Ready for commit\n    - `git add \u003cfile\u003e` adds a specific file to \"Staging\". Ready for commit.\n- `git commit -m \"Put Message Here\"` commits locally\n    - `git commit --amend`\" updates commit by amending your new changes to it. Must run after \"add\" command.\n    - `git commit --amend -m \"an updated commit message\"` updates the commit, and its commit message.\n- `git branch` says which branch we're on\n- `git push` pushes code to the branch we're on\n    - `git push origin \u003cmy_branch\u003e` pushes to specific branch. I think origin is a keyword.\n [Reference](https://www.digitalocean.com/community/tutorials/how-to-use-git-branches)\n- `git pull` pulls all changed files\n- `git cherry-pick \u003ccommit_number\u003e` adds a specific commit to your branch\n\n## More commands\n\n- `git rm \u003cfile\u003e` removes file from server (Must then do a commit, then push)\n- `git ls-files | xargs wc -l` counts # of lines of code in a github repo. [Link to Repo](https://gist.github.com/mandiwise/dc53cb9da00856d7cdbb)\n- `git config --global --edit` Edit git commit signature\n- `git branch -d the_local_branch` Removes local branch. [Link](https://makandracards.com/makandra/621-git-delete-a-branch-local-or-remote)\n- `git rebase -i HEAD~3` combines the last 3 commits into 1 commit. Called [Squashing Commits](http://gitready.com/advanced/2009/02/10/squashing-commits-with-rebase.html).\n- `git reset filename.txt` undoes adding a file.\n\n\n## Create repository\n\n1. In command line, type `git init \u003cproject name\u003e` to create a folder that's a Git repo.\n1. Add the repository to Github Desktop and push it through Github Desktop.\n\n## Clone Repository\n\n- `git clone https://github.com/noahprince22/GridWorldMDP.git` - clones repository and puts into same folder that command is run from. Repository will be in GridWorldMDP folder\n- `git clone https://github.com/noahprince22/GridWorldMDP.git putIntoThisFolder` - same as above but puts GridWorldMDP repository into _putIntoThisFolder_.\n\n## Submit changes\n\n1. `git status` to list new or modified files not yet committed\n1. `git add \u003cfile\u003e`\n1. `git commit -m \"\u003ccommit message\u003e\"`\n1. `git push` to push the code to the repository. If it fails since code needs to be pulled first, do:\n    1. `git pull` - this will do a `git fetch` and a `git merge`. (assuming no merge conflicts, go onto next steps)\n    1. `git push`\n\n\n## Revert changes\n\n1. `git revert \u003ccommit_number\u003e`\n1. then `:wq` to save in VIM\n1. then rebase\n\n\n## Rebase\n\n#### Rebasing with Merge Conflicts\n\n1. Commit my code on mainline\n1. `git pull --rebase`\n1. If merge conflicts, read the super-helpful tips in terminal. Basically just\n    1. Do a `git diff` to resolve the merge conflicts I have\n    1. I think next do a `git rebase --continue`\n\n#### Head is not on main branch - Put changes on top of head\n\nSomewhat useful [tutorial for git pull](https://www.atlassian.com/git/tutorials/syncing#git-remote)\n\n1. Do a `git log` to get the commit number corresponding to the changes you made. Save it for step 5.\n1. Get the branch we need. Try: `git pull origin \u003cbranch_name\u003e` or  `git checkout \u003cbranch\u003e`\n1. Do `git branch` to make sure we're on correct branch\n1. Do `git reset --hard \u003ccommit_number\u003e` using the actual 7-digit (or full) commit number, to put changes on top of branch we just switched to. Use commit number from step 1.\n1. If not on latest commit, do a `git pull --rebase`. Note: this command doesn't create a merge commit, so it makes other people's code diverge from what they had.\n\n\n## Stashing\n\n- `git stash` - moves your changes to a stash (a location where changes can be saved)\n- `git stash save \"Custom Message\"` - stashes changes, with custom message.\n- `git stash apply` - applies saved changes to your branch. Code also stays in stash.\n- `git stash pop` - applies saved changes to your branch. Code is removed stash.\n- `git stash show stash@{1} -p` - shows diff for stash@{1} (the 1st entry in the stash). Remove the `-p` to get abbreviated diff.\n- `git stash list` - shows all stashes.\n- [More stash commands](https://www.atlassian.com/git/tutorials/saving-changes/git-stash), and [even More stash commands](https://medium.freecodecamp.org/useful-tricks-you-might-not-know-about-git-stash-e8a9490f0a1a)\n\n__Stash topmost commit__\n\n1. `git reset HEAD^` - basically like an uncommit\n1. `git stash` (this may not stash new files. Maybe try \"tracking\" the new files to see if this works)\n\n\n## Merge Branch\n\nTo merge 1 branch into another, go to the \"giving branch\" and do a `git pull`. Then go to receiving branch, and run 1 of the following merge commands:\n- `git merge \u003cbranch_name\u003e` - Run this from receiving branch. More info [here](https://www.atlassian.com/git/tutorials/using-branches/git-merge)\n- `git merge \u003ccommit_number_from_another_branch\u003e` - Merges another branch (up to the commit number) into this branch.\n\n\n## Create new branch and upstream it\n\n- `git checkout -b myNewBranch` - creates branch\n- `git push --set-upstream origin myNewBranch` - [tells the remote server that a new branch has been created locally, so that it can recreate the same branch](https://www.datree.io/resources/git-create-branch)\n\n\n## Troubleshoot\n\n__\"Checkout\" or \"Pull\" not working__\n\nCommon mistake is to modify files on local machine, and then try to do a \"checkout\" or \"pull\". Problem is the checkout/pull will overwrite what we have. If we do want to OVERWRITE our files, we can erase our changes by typing `git reset --hard HEAD`. Then we can checkout/pull without problems, which gets us the remote files.\n\n## Links\n\n[Fun way to learn git](https://learngitbranching.js.org)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frodneyshag%2Fgit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frodneyshag%2Fgit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frodneyshag%2Fgit/lists"}