{"id":15410784,"url":"https://github.com/rehansaeed/git-cheat-sheet","last_synced_at":"2026-02-07T17:05:26.195Z","repository":{"id":39585243,"uuid":"113461259","full_name":"RehanSaeed/Git-Cheat-Sheet","owner":"RehanSaeed","description":"A cheat sheet for uncommon Git commands.","archived":false,"fork":false,"pushed_at":"2022-08-02T07:46:29.000Z","size":43,"stargazers_count":65,"open_issues_count":0,"forks_count":55,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-06-02T05:11:53.249Z","etag":null,"topics":["cheat-sheet","git"],"latest_commit_sha":null,"homepage":"","language":"PowerShell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/RehanSaeed.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-12-07T14:34:07.000Z","updated_at":"2025-04-08T23:45:44.000Z","dependencies_parsed_at":"2022-07-11T02:31:47.918Z","dependency_job_id":null,"html_url":"https://github.com/RehanSaeed/Git-Cheat-Sheet","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/RehanSaeed/Git-Cheat-Sheet","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RehanSaeed%2FGit-Cheat-Sheet","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RehanSaeed%2FGit-Cheat-Sheet/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RehanSaeed%2FGit-Cheat-Sheet/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RehanSaeed%2FGit-Cheat-Sheet/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/RehanSaeed","download_url":"https://codeload.github.com/RehanSaeed/Git-Cheat-Sheet/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RehanSaeed%2FGit-Cheat-Sheet/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265024279,"owners_count":23699589,"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":["cheat-sheet","git"],"created_at":"2024-10-01T16:46:22.712Z","updated_at":"2026-02-07T17:05:26.144Z","avatar_url":"https://github.com/RehanSaeed.png","language":"PowerShell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Git-Cheat-Sheet\r\nA cheat sheet for uncommon Git commands\r\n\r\n## Configuration\r\n| Command | Description |\r\n| - | - |\r\n| `git config --global user.name \"foo\"`              | Set user name |\r\n| `git config --global user.email \"foo@example.com\"` | Set user email |\r\n\r\n## Branches\r\n| Command | Description |\r\n| - | - |\r\n| `git branch foo`                          | Create a new branch |\r\n| `git branch -d foo`                       | Deletes a branch |\r\n| `git switch foo`                          | Switch to a branch |\r\n| `git switch -c\\|--create foo`             | Create and switch to a branch |\r\n| `git restore foo.js`                      | Undo all changes on the foo.js file |\r\n| `git checkout foo.js`                     | Undo all changes on the foo.js file |\r\n| `git checkout foo`                        | Use `git switch` instead |\r\n| `git checkout -b foo`                     | Use `git switch -c` instead |\r\n| `git merge foo`                           | Merge branch into current branch |\r\n\r\n## Pulling\r\n| Command | Description |\r\n| - | - |\r\n| `git pull --rebase --prune`               | Get latest, rebase any changes not checked in and delete branches that no longer exist | \r\n\r\n## Staged Changes\r\n| Command | Description |\r\n| - | - |\r\n| `git add file.txt`                        | Stage file |\r\n| `git add -p`|--patch file.txt`            | Stage some but not all changes in a file |\r\n| `git mv file1.txt file2.txt`              | Move/rename file |\r\n| `git rm --cached file.txt`                | Unstage file |\r\n| `git rm --force file.txt`                 | Unstage and delete file |\r\n| `git reset HEAD`                          | Unstage changes |\r\n| `git reset --hard HEAD`                   | Unstage and delete changes |\r\n| `git clean -f\\|--force -d`                | Recursively remove untracked files from the working tree |\r\n| `git clean -f\\|--force -d -x`             | Recursively remove untracked and ignored files from the working tree |\r\n\r\n## Changing Commits\r\n| Command | Description |\r\n| - | - |\r\n| `git reset 5720fdf`                           | Reset current branch but not working area to commit |\r\n| `git reset HEAD~1`                            | Reset the current branch but not working area to the previous commit |\r\n| `git reset --hard 5720fdf`                    | Reset current branch and working area to commit |\r\n| `git commit --amend -m \"New message\"`         | Change the last commit message |\r\n| `git commit --fixup 5720fdf -m \"New message\"` | Merge into the specified commit |\r\n| `git revert 5720fdf`                          | Revert a commit |\r\n| `git rebase --interactive [origin/main]`      | Rebase a PR (`git pull` first) |\r\n| `git rebase --interactive 5720fdf`            | Rebase to a particular commit |\r\n| `git rebase --interactive --root 5720fdf`     | Rebase to the root commit |\r\n| `git rebase --continue`                       | Continue an interactive rebase |\r\n| `git rebase --abort`                          | Cancel an interactive rebase |\r\n| `git cherry-pick 5720fdf`                     | Copy the commit to the current branch |\r\n\r\n## Compare\r\n| Command | Description |\r\n| - | - |\r\n| `git diff`                                | See difference between working area and current branch |\r\n| `git diff HEAD HEAD~2`                    | See difference between te current commit and two previous commits |\r\n| `git diff main other`                     | See difference between two branches |\r\n\r\n## View\r\n| Command | Description |\r\n| - | - |\r\n| `git log`                                 | See commit list |\r\n| `git log --patch`                         | See commit list and line changes |\r\n| `git log --decorate --graph --oneline`    | See commit visualization |\r\n| `git log --grep foo`                      | See commits with foo in the message |\r\n| `git show HEAD`                           | Show the current commit |\r\n| `git show HEAD^` or `git show HEAD~1`     | Show the previous commit |\r\n| `git show HEAD^^` or `git show HEAD~2`    | Show the commit going back two commits |\r\n| `git show main`                           | Show the last commit in a branch |\r\n| `git show 5720fdf`                        | Show named commit |\r\n| `git blame file.txt`                      | See who changed each line and when |\r\n\r\n## Stash\r\n| Command | Description |\r\n| - | - |\r\n| `git stash push -m \"Message\"`             | Stash staged files |\r\n| `git stash --include-untracked`           | Stash working area and staged files |\r\n| `git stash --staged`                      | Stash staged files |\r\n| `git stash list`                          | List stashes |\r\n| `git stash apply`                         | Moved last stash to working area |\r\n| `git stash apply 0`                       | Moved named stash to working area |\r\n| `git stash clear`                         | Clear the stash |\r\n\r\n## Tags\r\n| Command | Description |\r\n| - | - |\r\n| `git tag`                                              | List all tags |\r\n| `git tag -a\\|--annotate 0.0.1 -m\\|--message \"Message\"` | Create a tag |\r\n| `git tag -d\\|--delete 0.0.1`                           | Delete a tag |\r\n| `git push --tags`                                      | Push tags to remote repository |\r\n\r\n## Remote\r\n| Command | Description |\r\n| - | - |\r\n| `git remote -v`                           | List remote repositories |\r\n| `git remote show origin`                  | Show remote repository details |\r\n| `git remote add upstream \u003curl\u003e`           | Add remote upstream repository |\r\n| `git fetch upstream`                      | Fetch all remote branches |\r\n| `git rebase upstream/main`                | Refresh main branch from upstream |\r\n| `git remote -v`                           | List remote repositories |\r\n| `git push --force`                        | Push any changes while overwriting any remote changes |\r\n| `git push --force-with-lease`             | Push any changes but stop if there are any remote changes |\r\n| `git push --tags`                         | Push tags to remote repository |\r\n\r\n## Submodules\r\n| Command | Description |\r\n| - | - |\r\n| `git submodule status`                    | Check status of all submodules |\r\n\r\n- Pull submodules\r\n  1. `git submodule sync`\r\n  2. `git submodule init`\r\n  3. `git submodule update`\r\n- Change branch\r\n  1. `cd /submodule`\r\n  2. `git fetch origin \u003cbranch-name\u003e`\r\n  3. `git checkout \u003cbranch-name\u003e`\r\n  4. `cd /`\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frehansaeed%2Fgit-cheat-sheet","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frehansaeed%2Fgit-cheat-sheet","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frehansaeed%2Fgit-cheat-sheet/lists"}