{"id":18835346,"url":"https://github.com/ashwanikumar04/git-cheatsheet","last_synced_at":"2025-06-28T00:03:41.626Z","repository":{"id":88929156,"uuid":"155716797","full_name":"ashwanikumar04/git-cheatsheet","owner":"ashwanikumar04","description":"Common commands for Git","archived":false,"fork":false,"pushed_at":"2018-11-19T03:39:02.000Z","size":3,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-29T18:20:20.629Z","etag":null,"topics":["cheatsheet","git"],"latest_commit_sha":null,"homepage":"http://blog.ashwanik.in/2018/11/most-common-git-commands-git-cheat-sheet.html","language":null,"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/ashwanikumar04.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-11-01T13:10:08.000Z","updated_at":"2019-07-15T17:09:03.000Z","dependencies_parsed_at":"2023-03-13T18:17:39.623Z","dependency_job_id":null,"html_url":"https://github.com/ashwanikumar04/git-cheatsheet","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ashwanikumar04/git-cheatsheet","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ashwanikumar04%2Fgit-cheatsheet","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ashwanikumar04%2Fgit-cheatsheet/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ashwanikumar04%2Fgit-cheatsheet/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ashwanikumar04%2Fgit-cheatsheet/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ashwanikumar04","download_url":"https://codeload.github.com/ashwanikumar04/git-cheatsheet/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ashwanikumar04%2Fgit-cheatsheet/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262352534,"owners_count":23297682,"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","git"],"created_at":"2024-11-08T02:15:55.079Z","updated_at":"2025-06-28T00:03:41.586Z","avatar_url":"https://github.com/ashwanikumar04.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"This document lists some of the common commands used for `Git`.\n\n# Cheat Sheet\n- [Cheat Sheet](#cheat-sheet)\n  * [Commands](#commands)\n    + [History](#history)\n      - [Detailed](#detailed)\n      - [Short](#short)\n      - [Pretty](#pretty)\n    + [Clone](#clone)\n      - [Https](#https)\n      - [SSH](#ssh)\n      - [Single branch](#single-branch)\n    + [Config](#config)\n      - [Local](#local)\n      - [Global](#global)\n      - [Alias](#alias)\n    + [Status](#status)\n    + [Add](#add)\n    + [Commit](#commit)\n      - [Undo](#undo)\n      - [Commit](#commit-1)\n    + [Checkout](#checkout)\n    + [Stash](#stash)\n    + [Push](#push)\n    + [Pull](#pull)\n  * [References](#references)\n\n## Commands\n\n### History \n\n#### Detailed\n\n```sh\n\ngit log\n\n```\n\n#### Short\n\n```sh\n\ngit shortlog\n\n```\n\n```sh\n\ngit log --oneline --no-merges\n\n```\n\n#### Pretty\n\n```sh\ngit config --global alias.lg \"log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)\u003c%an\u003e%Creset' --abbrev-commit --date=relative\"\n```\n\n```\ngit lg\n```\n\n### Clone\n\n#### Https\n\n```sh\ngit clone https://github.com/ashwanikumar04/git-cheatsheet.git\n```\n\n#### SSH\n\n```sh\ngit clone git@github.com:ashwanikumar04/git-cheatsheet.git\n\n```\n#### Single branch\nSometimes when the repository is very large, we only want to clone a single branch. Use below command to clone a single branch\n```sh\ngit clone git@github.com:ashwanikumar04/git-cheatsheet.git -b master --single-branch\n\n```\n\n### Config\n\nThe following command makes the output of git commands colorful.\n```sh\ngit config --global color.ui true\n```\n\n#### Local\n\n```sh\ngit config user.name \"Ashwani Kumar\"\ngit config user.email \"ashwanikumar@test.com\"\n```\n\n#### Global\n\n\n```sh\ngit config --global user.name \"Ashwani Kumar\"\ngit config --global user.email \"ashwanikumar@test.com\"\n```\n\n#### Alias\n\n```sh\ngit config --global alias.st status\n```\nJust type `git st` whenever we want to see the status of the repository\n\n\n```sh\ngit config --global alias.co checkout\n```\nJust type `git co` whenever we want to check out a branch\n\n\n```sh\ngit config --global alias.st status\n```\nJust type `git ci` whenever we want run a commit\n\n### Status\n\n`git status` Shows the status with tracked and un-tracked files\n\n### Add\n\n```git add .``` Adds all the files in the current directory to staging.\n\n```git add -A``` Adds all files in the current repository (even new files that are not yet tracked)\n\n```git add -u```  Add all files that are already being tracked (ignore new files)\n\n### Commit\n\n#### Undo\n\n`git reset --soft HEAD^` Undo last commit of entire repo, but leave files staged.\n\n`git reset --hard HEAD^` Completely blow away last commit. Changes files to state of previous commit.\n\n`git reset --hard HEAD^^` Completely blow away last two commits. Changes files to state of previous commit.\n\n`git reset --hard HEAD^^^` Completely blow away last three commits. Changes files to state prior to last third commit.\n\n\n**Returns files to state they were in, after specified commit**\n\n```sh\ngit reset --hard \u003csha-of-commit\u003e\n\ngit push origin HEAD --force\n\n```\n\n#### Commit\n\n`git commit -m \"Add file to repository\"` Commit staged files to the repository\n\n`git commit --amend -m \"New Message\"` Changes the commit message for the last commit\n\n`git commit -am \"New Message\"` Lets us add and commit all tracked, modified files in one step.\n\n### Checkout\n\n`git checkout -b \u003cname_of_branch\u003e` Create a branch and check it out in one step\n\n`git branch \u003cname_of_branch\u003e` Create a branch, but stay in current branch.\n\n`git checkout \u003cname_of_branch\u003e` Check out an already created branch\n\n`git branch` See a list of all branches, highlights the currently checked out branch\n\n`git checkout master` Checkout master branch\n\n`git branch -d \u003cname_of_branch\u003e` Remove branch locally, but only if we have merged branch.\n\n`git branch -D \u003cname_of_branch\u003e` Remove branch even if we haven't merged changes.\n\n### Stash\n\n`git stash` Use this to stash all the changes to the current repository\n\n`git stash apply` Use this to apply the last stash\n\n### Push\n\n`git push --set-upstream origin \u003cbranch\u003e`\n`git push`\n\n### Pull\n\n`git pull origin/master`\n\n\n## References\n\n1. [Treehouse](https://github.com/treehouse-dave/get-acquainted-with-git)\n2. [CheatSheet](https://github.com/vasanthk/git-tips-and-tricks)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fashwanikumar04%2Fgit-cheatsheet","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fashwanikumar04%2Fgit-cheatsheet","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fashwanikumar04%2Fgit-cheatsheet/lists"}