{"id":21829891,"url":"https://github.com/andreia/omgit","last_synced_at":"2025-04-14T06:21:13.829Z","repository":{"id":137287471,"uuid":"324854218","full_name":"andreia/OMGit","owner":"andreia","description":"Git Quick Reference","archived":false,"fork":false,"pushed_at":"2024-04-13T20:33:39.000Z","size":19161,"stargazers_count":24,"open_issues_count":0,"forks_count":9,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-03-27T20:06:36.867Z","etag":null,"topics":["cheatsheet","cli","git","github","quickreference","reference"],"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/andreia.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":"2020-12-27T21:43:34.000Z","updated_at":"2024-12-09T00:26:00.000Z","dependencies_parsed_at":null,"dependency_job_id":"df7685af-b134-4f42-aa70-708a3d113189","html_url":"https://github.com/andreia/OMGit","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/andreia%2FOMGit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andreia%2FOMGit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andreia%2FOMGit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andreia%2FOMGit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/andreia","download_url":"https://codeload.github.com/andreia/OMGit/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248830876,"owners_count":21168359,"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":["cheatsheet","cli","git","github","quickreference","reference"],"created_at":"2024-11-27T18:32:57.367Z","updated_at":"2025-04-14T06:21:13.811Z","avatar_url":"https://github.com/andreia.png","language":null,"readme":"# OMGit! \u003c3\nGit Quick Reference\n\n- [PDF Format](https://github.com/andreia/OMGit/blob/main/pdf/git_quick_reference.pdf) \n- [Image Format](https://github.com/andreia/OMGit/blob/main/images/git_quick_reference.png)\n\n![Git Cheat Sheet Image](https://github.com/andreia/OMGit/blob/main/images/git_quick_reference_small.jpg?raw=true)\n\n## Setting up\n\n### Set author name\n(to be show on version history)\n\n```console\ngit config --global user.name \"\u003cfirstname lastname\u003e\"\n```\ne.g.:\n```console\ngit config --global user.name \"Andréia Bohner\"\n```\n\n### Set email address\n\n```console\ngit config --global user.email \"\u003cemail\u003e\"\n```\n\n### Change author's name and email\n\n```console\ngit commit --amend --author=\"\u003cfirstname lastname\u003e \u003c\u003cemail\u003e\u003e\" --no-edit\n```\n\n### Set automatic CLI coloring for Git\n\n```console\ngit config --global color.ui auto\n```\n\n### Configure line-ending (CRLF)\n\n```console\ngit config core.autocrlf\n```\nshow current CRLF config\n\n```console\ngit config --global core.autocrlf \u003cinput|true|false\u003e\n```\nset line-ending style\n\n- ```input```: convert crlf to lf on commit but not the other way around\n- ```false```: turn off crlf\n- ```true```: converts lf endings into crlf\n\ne.g.: \n```console\ngit config --global core.autocrlf input\n```\n\n### List all Git config settings\n\n```console\ngit config --list\n```\n\n## Workflow\n\n### Create a new repository from current local directory (local files)\n\n```console\ngit init \u003crepository_name\u003e\n```\n\n### Create a new repository locally from a remote repository\n\n```console\ngit clone \u003crepository_url\u003e\n```\ne.g:\n```console\ngit clone https://github.com/path/repository.git\n```\n\n### Create a new branch\n\nCreate a new branch based on `[base_branch]` or on current branch if `[base_banch]` isn't informed\nand check it out right away:\n\n```console\ngit checkout -b \u003cbranch_name\u003e [base_banch]\n```\n\nCreate a new branch based on current branch and stays on current branch:\n\n```console\ngit branch \u003cbranch_name\u003e\n```\n\n### List all local branches\n\n```console\ngit branch\n```\n\n### List all local and remote branches\n\n```console\ngit branch -a\n```\n\n### List all tracking branches, their upstreams, last commit on branch, and if local branch is ahead, behind, or both\n\n```console\ngit branch -vv\n```\n\n### List all branches merged into the specified branch\n\n```console\ngit branch --merged \u003cbranch_name\u003e\n```\n\n### Get new changes, branches, and tags from remote repository\n(just get the changes, it doesn't merge them)\n\n```console\ngit fetch \u003cremote_name\u003e\n```\n\nit's usually:\n\n```console\ngit fetch origin\n```\n\n### Check changes on current branch\n\n```console\ngit status\n```\n\nShow the status of your working directory: \n- new, staged, and modified files.\n- current branch name\n- current commit identifier\n- changes pending to commit\n\n### Add a local changed file to stage area\n\n```console\ngit add \u003cpath/to/file.txt\u003e\n```\n\n### Add all local changes to stage area\n\n```console\ngit add .\n```\n\n### Commit staged local changes on current local branch\n\n```console\ngit commit -m \"commit message\"\n```\n\n### Add all local files to stage area and commit, with one line:\n\n```console\ngit commit -am \"Commit message\"\n```\n\nEquivalent to:\n\n```console\ngit add .\ngit commit -m \"Commit message\"\n```\n\n### Add missing file on last local commit\n\n```console\ngit add missing_file.txt\ngit commit --amend --no-edit\n```\n\n### Empty commit\n\n```console\ngit commit  --allow-empty\n```\n\n### Change to another local branch\n\n```console\ngit checkout \u003cbranch_name\u003e\n```\n\n### Back to the previous branch\n\n```console\ngit checkout -\n```\n\nor:\n\n```console\ngit checkout @{-1}\n```\n\n### Get a remote branch locally\n\n```console\ngit fetch origin\ngit checkout \u003cremote_branch_name\u003e\n```\nor:\n```console\ngit checkout -t origin/\u003cremote_branch_name\u003e\n```\n\n### Merge another local branch on current local branch\n\n```console\ngit merge \u003cbranch_name_to_merge_on_current_branch\u003e\n```\n\n### Merge changes from a remote branch on current local branch\n\n(fetch from remote and merge into local)\n\n```console\ngit pull origin \u003cremote_branch_name\u003e\n```\n\n#### Pick a commit from a branch and apply it to another\n\n```console\ngit cherry-pick \u003ccommit_hash\u003e\n```\n\n### Conflicts\n\n#### Resolve merge conflicts in favor of pulled changes during a pull\n\n```console\ngit checkout --theirs \u003cpath/to/file.txt\u003e\n```\n\n#### Resolve merge conflicts in favor of my local changes during a pull\n\n```console\ngit checkout --ours \u003cpath/to/file.txt\u003e\n```\n\nE.g.:\n\n```console\ngit checkout --ours package-lock.json\n```\n\n### Push local changes to a remote branch\n\n```console\ngit push origin \u003cremote_branch_name\u003e\n```\n\n- `-u`: add upstream (tracking) reference\n```console\ngit push -u origin \u003cremote_branch_name\u003e\n```\n\n- `--tags`: push also the tags\n```console\ngit push --tags origin \u003cremote_branch_name\u003e\n```\n\n- `--force`: if there are changes on remote branch that aren't in local branch (command refuses to update the remote), and you want to overwrite them:\n```console\ngit push --force origin \u003cremote_branch_name\u003e\n```\n\nNote: You can use `HEAD` instead of `\u003cremote_branch_name\u003e`:\n```console\ngit push origin HEAD\n```\n\nHEAD is the current branch on your local repository:\n\n```console\ncat .git/HEAD\nref: refs/heads/\u003cname_of_the_branch\u003e\n```\n\n### Force push and ensure you don't overwrite work from others\n\n```console\ngit push --force-with-lease origin \u003cbranch_name\u003e\n```\n\n### List all operations made on local repository\n\ne.g.: commits, checkouts, pull, ... (also list removed commits with `git reset`, `git rebase`, ...) \n\n```console\ngit reflog\n```\n\n### Have to work on another branch. What to do with the changes on current branch?\n\nMove them to stash: a place to temporarily store the modified and staged files in order to change branches.\n\n#### Put the current working directory changes into stash, for later use\n```console\ngit stash\n```\n\n#### Put the current working directory changes into stash with a message\n```console\ngit stash push -m \u003cmessage\u003e\n```\n\n#### Put the current working directory changes into stash, including untracked files\n```console\ngit stash -u\n```\nor\n```console\ngit stash push -u\n```\nor\n```console\ngit stash push --include-untracked\n```\n\n#### Add all changed files of the current working directory into stash (ignored, untracked, and tracked)\n```console\ngit stash -a\n```\nor\n```console\ngit stash --all\n```\nor\n```console\ngit stash push --all\n```\n\n#### List all saved stashes\n\n```console\ngit stash list\n```\n\n#### Show the contents of a specific stash in patch form\n\n```console\ngit stash show -p \u003cstash@{n}\u003e\n```\n\n#### Get the stored stash content into working directory, and drop it from stash.\n\n```console\ngit stash pop\n```\n\n#### Apply the content of a specific stash without removing it from the stashed list\n\n```console\ngit stash apply \u003cstash@{n}\u003e\n```\n\n## Checking changes\n\n### Unstaged changes\n\n```console\ngit diff\n```\n\n### Changes staged but not commited\n\n```console\ngit diff --staged\n```\nor\n```console\ngit diff --cached\n```\n\n### Staged and unstaged changes\n\n```console\ngit diff HEAD\n```\n\n### All files with conflict\n\n```console\ngit diff --name-only --diff-filter=U\n```\n\n### Show only changed files\n```console\ngit show --name-only\n```\n\n### Changes since a provided period\n```console\ngit log --no-merges --raw --since='2 weeks ago'\n```\nor:\n```console\ngit whatchanged --since='2 weeks ago'\n```\n\n### Search commits by content\n```console\ngit log -S '\u003ccontent to search\u003e'\n```\n\n### Search by commit message\n```console\ngit log --all --grep='content to search'\n```\nor\n```console\ngit log --oneline | grep -F 'content to search'\n```\n\n### Search all changes for specific file\n```console\ngit log -p \u003cpath/to/file.txt\u003e\n```\n\n### All changed files on specific commit\n```console\ngit diff-tree --no-commit-id --name-only -r \u003ccommit_sha\u003e\n```\n\n### Show all commits (Git history)\n(history as a one-line short message - sha \u0026 message)\n\n```console\ngit log --oneline --graph --all\n```\n\n### Summary of the commits grouped by author\n(with the first line of each commit message)\n\n```console\ngit shortlog\n```\n\n## Rename Things\n\n### Rename a local branch\n\n```console\ngit branch -m \u003cold_name\u003e \u003cnew_name\u003e\n```\n\n### Rename a remote branch\n\n1. Delete the current remote branch:\n```console\ngit push origin --delete \u003cold_name\u003e\n```\n\n2. Push the new local branch with the new name:\n```console\ngit push -u origin \u003cnew_name\u003e\n```\n\n### Rename an existing remote name\n\nList your existing remotes to get the name of the remote you want to change:\n\n```console\ngit remote -v\n\n\u003e origin  https://github.com/USERNAME/REPOSITORY.git (fetch)\n\u003e origin  https://github.com/USERNAME/REPOSITORY.git (push)\n```\n\nRename the remote from `old_name` to `new_name`:\n\n```console\ngit remote rename \u003cold_name\u003e \u003cnew_name\u003e\n```\n\nE.g.:\n\n```console\ngit remote rename origin production\n```\n\nCheck that the remote URL has changed:\n\n```console\ngit remote -v\n\n\u003e production  https://github.com/USERNAME/REPOSITORY.git (fetch)\n\u003e production  https://github.com/USERNAME/REPOSITORY.git (push)\n```\n\n### Rename the remote url of an existing local repository to match the renamed remote repository\n\nTo rename the existing local repository accordingly to the remote you can first\nrename the repository directory (optional) and then, to rename the remote URL\nto the new name:\n\nList your existing remotes:\n\n```console\ngit remote -v\n\n\u003e origin  https://github.com/USERNAME/REPOSITORY.git (fetch)\n\u003e origin  https://github.com/USERNAME/REPOSITORY.git (push)\n```\n\nRename the remote URL to `new_url`:\n\n```console\ngit remote set-url \u003cremote_name\u003e \u003cnew_url\u003e\n```\n\n- `\u003cremote_name\u003e` could be `origin` or `upstream` for example\n- `\u003cnew_url\u003e` could be the HTTPS or SSH URL\n\nChange the `origin` remote's HTTPS URL e.g.:\n\n```console\ngit remote set-url origin https://github.com/USERNAME/NEW-REPOSITORY.git\n```\n\nChange the `origin` remote's SSH URL e.g.:\n\n```console\ngit remote set-url origin git@github.com:USERNAME/NEW-REPOSITORY.git\n```\n\nCheck that the remote URL has changed:\n\n```console\ngit remote -v\n\n\u003e origin  https://github.com/USERNAME/NEW-REPOSITORY.git (fetch)\n\u003e origin  https://github.com/USERNAME/NEW-REPOSITORY.git (push)\n```\n\n### Rename a file\n\n```console\ngit mv \u003cold_name\u003e \u003cnew_name\u003e\ngit commit -m \"renamed\"\ngit push origin main\n```\n\n## Undo Things\n\n### Unstage a file\n(retain the changes in working directory)\n\n```console\ngit reset HEAD \u003cpath/to/file.txt\u003e\n```\n\n### Unstage all files\n(retain the changes in working directory)\n\n```console\ngit reset HEAD -- .\n```\n\n### Discard changes on unstaged file in working directory\n(changes to the modified file are discarded)\n\n```console\ngit checkout -- \u003cpath/to/file.txt\u003e\n```\n\n### Discard changes on all unstaged files in working directory\n(changes to the modified files are discarded)\n\n```console\ngit checkout .\n```\n\n### Undo local unpushed commit\n(most recent commit)\n\nKeep the work done on last commit (files will show in the stage\narea as an uncommitted change):\n\n```console\ngit reset --soft HEAD^\n```\n\n```console\ngit reset HEAD~\n```\n\n```console\ngit reset HEAD \u003cpath/to/file.txt\u003e\n```\n\nDelete all the work done on last commit:\n\n```console\ngit reset --hard HEAD~1\n```\n\n### Reverting changes\n\n```console\ngit reset [--hard] \u003ctarget_reference\u003e\n```\n\nSwitch the current branch to the target reference,\nleaving a difference as an uncommitted change:\n\n```console\ngit reset origin/master\n```\n\nSwitch the current branch to the target reference,\ndiscarding all changes\n\n```console\ngit reset --hard origin/master\n```\n\n### Reverting changes of a specific commit\n\n(Create a new commit, reverting changes from the specified commit.\nIt generates an inversion of changes.)\n\n```console\ngit revert \u003ccommit_sha\u003e\n```\n\n### Reverting local changes to a relative time\n\n```console\ngit reset --hard HEAD@{3.minutes.ago}\n```\n\n### Change the last (unpushed) commit message\n\n```console\ngit commit --amend -m \"New message here\"\n```\n\n### Untrack files without deleting on working directory\n\n```console\ngit rm --cached \u003cpath/to/file.txt\u003e\n```\n\n### Discard all uncommitted changes on local working directory\n(uncommitted changes will be removed)\n\n```console\ngit restore .\n```\n\n### Revert local commits added on wrong branch and add them to the correct branch\n\n```console\ngit branch \u003ccorrect_branch_name\u003e\ngit reset --hard \u003ctarget_reference\u003e\ngit checkout \u003ccorrect_branch_name\u003e\n```\n\nExample: add local commits on correct `fix_typo` branch, remove them from the `master` branch, and checkout `fix_typo` branch:\n\n```console\ngit branch fix_typo\ngit reset --hard origin/master\ngit checkout fix_typo\n```\n\n## Removing\n\n### Remove local branch\n\n```console\ngit branch -d \u003cbranch_name\u003e\n```\n- `-D` instead of `-d` forces deletion\n\n### Remove remote branch\n\n```console\ngit push --delete \u003cremote_name\u003e \u003cbranch_name\u003e\n```\ne.g.:\n```console\ngit push --delete origin my_remote_branch\n```\n\n### Remove file from working directory and Git repo\n```console\ngit rm \u003cpath/to/file.txt\u003e\n```\n\n### Remove a tag from local repository\n\n```console\ngit tag -d \u003cname\u003e\n```\n\n### Remove a tag from remote repository\n\n```console\ngit push --delete origin \u003ctag_name\u003e\n```\nor:\n```console\ngit push origin :refs/tags/tag_name\n```\n\n### Remove changes from stash\n\nRemove the `[stash_name]` informed or the last one if none is provided.\n```console\ngit stash drop [stash_name]\n```\ne.g.:\n```console\ngit stash drop stash@{0}\n```\n\n### Remove all stored stashes\n\n```console\ngit stash clear\n```\n\n### Remove untracked files\n(Remove untracked files. Modified files are unchanged)\n\n```console\ngit clean -f\n```\n\n### Remove untracked files and directories\n(Remove untracked files and directories. Modified files are unchanged)\n\n```console\ngit clean -f -d\n```\n\n## Tagging\n\nTypes of tags:\n- `lightweight`: just the commit checksum stored in a file, i.e., a pointer to a specific commit\n- `annotated`: stored as full objects in Git (checksummed; contain the tagger name, email, and date; have a tagging message; and can be signed and verified with GNU Privacy Guard - GPG).\n\n### List all tags\n\n```console\ngit tag\n```\n\n### Show the current tag you are\n\n```console\ngit describe --tags\n```\n\n### Create a lightweight tag for current commit or for [commit sha], if informed.\n\n```console\ngit tag \u003ctag_name\u003e [commit_sha]\n```\n\n### Create an annoted tag for current commit if [commit sha] it's not informed \n\n```console\ngit tag -a \u003ctag_name\u003e [commit_sha] [-m \"tagging_message\"]\n```\ne.g.: \n```console\ngit tag -a v2.1 -m \"version 2.1\"\n```\n\n### Show tag data with the commit that was tagged\n\n```console\ngit show \u003ctag_name\u003e\n```\ne.g.:\n```console\ngit show v2.1\n```\n\n## Remote\n\n### List all remote references\n\n```console\ngit remote\n```\n\n### Change the remote's URL from SSH to HTTPS:\n\n```console\ngit remote set-url origin https://github.com/USERNAME/REPOSITORY.git\n```\n\n### Change the remote's URL from HTTPS to SSH:\n\n```console\ngit remote set-url origin git@github.com:USERNAME/REPOSITORY.git\n```\n\n## Notes\n\n### Add object notes\n\n```console\ngit notes add -m 'Note message here'\n```\n\n### Show all notes\n\n```console\ngit log --show-notes='*'\n```\n\n## More useful commands\n\n### Git help guide\n```console\ngit help -g\n```\n\n### Git web-based UI\n```console\ngit instaweb --httpd apache2\ngit instaweb --httpd nginx\ngit instaweb --httpd=webrick\n```\n\n### Sync with remote, overwrite local changes\n```console\ngit fetch origin \u0026\u0026 git reset --hard origin/\u003cbranch_name\u003e \u0026\u0026 git clean -f -d\n```\n\n### Find the commit that has introduced a bug in the code (using binary search)\n```console\ngit bisect start\ngit bisect bad\ngit bisect good\n```\n\n## References\n\n- https://git-scm.com/\n- https://docs.github.com/en/get-started/getting-started-with-git/managing-remote-repositories\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandreia%2Fomgit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fandreia%2Fomgit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandreia%2Fomgit/lists"}