{"id":19021638,"url":"https://github.com/buildwithlal/git-cheatsheet","last_synced_at":"2026-04-28T16:30:19.199Z","repository":{"id":144099523,"uuid":"111851848","full_name":"BuildWithLal/Git-cheatsheet","owner":"BuildWithLal","description":"List of all basic and minimum Git commands with one line explanation","archived":false,"fork":false,"pushed_at":"2017-11-24T14:52:30.000Z","size":10,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-02T00:42:32.431Z","etag":null,"topics":["git","git-cheatsheet"],"latest_commit_sha":null,"homepage":"","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/BuildWithLal.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":"2017-11-23T21:34:02.000Z","updated_at":"2024-12-17T17:28:31.000Z","dependencies_parsed_at":"2023-04-12T02:46:35.519Z","dependency_job_id":null,"html_url":"https://github.com/BuildWithLal/Git-cheatsheet","commit_stats":null,"previous_names":["buildwithlal/git-cheatsheet"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BuildWithLal%2FGit-cheatsheet","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BuildWithLal%2FGit-cheatsheet/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BuildWithLal%2FGit-cheatsheet/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BuildWithLal%2FGit-cheatsheet/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/BuildWithLal","download_url":"https://codeload.github.com/BuildWithLal/Git-cheatsheet/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240065861,"owners_count":19742580,"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","git-cheatsheet"],"created_at":"2024-11-08T20:22:51.032Z","updated_at":"2026-04-28T16:30:19.161Z","avatar_url":"https://github.com/BuildWithLal.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"### Git Cheatsheet\n\n##### List of all basic and minimum Git commands\n\n\u003cbr/\u003e\n\n```\nWorking Area –-\u003e git add file --\u003e Staging Area –-\u003e git commit --\u003e Commit Area\n```\n\n\u003cbr/\u003e\n\n```\ngit init\n```\n\nInitiate `.git` directory in current working directory.\n\n\u003cbr/\u003e\n\n```\ngit init cookbook\n```\n\nCreate `cookbook` directory and initiate `.git` directory inside `cookbook` directory\n\n\u003cbr/\u003e\n\n```\ngit add file\n```\n\nAdd file to staging area\n\n\u003cbr/\u003e\n\n```\ngit add .\n```\n\nAdd all files to staging area\n\n\u003cbr/\u003e\n\n```\ngit rm file\n```\n\nRemove file from staging area. In next commit, file will be deleted. Require `-f` if file is already modified and still exist\nin staging area\n\n\u003cbr/\u003e\n\n```\ngit rm --cached file\n```\n\nRemove file from staging area and keeps in working directory as untracked\n\n\u003cbr/\u003e\n\n```\nrm file\n```\n\nRemove file from working area. If already in staging area then need `git add/rm` to include it in\nnext commit for deletion\n\n\u003cbr/\u003e\n\n```\ngit commit -m \"message\"\n```\n\nMove staging area files to commit area\n\n\u003cbr/\u003e\n\n```\ngit commit -a -m \"message\"\n```\n\nAdd files to staging area and then move from staging area to commit area. This command is equal to `git add .` and then `git commit -m \"message\"`\n\n\u003cbr/\u003e\n\n```\ngit log\n```\n\nList all the commits of current branch\n\n\u003cbr/\u003e\n\n```\ngit log -p\n```\n\nList all commits with difference in each two commits\n\n\u003cbr/\u003e\n\n```\ngit log -2\n```\n\nShow last 2 commits from current branch\n\n\u003cbr/\u003e\n\n```\ngit log –oneline\n```\n\nShow oneline detail about each commit incluing commit hash and commit message.\n\n\u003cbr/\u003e\n\n```\ngit show\n```\n\nShow details of last commit from current branch\n\n\u003cbr/\u003e\n\n```\ngit show commit_hash\n```\n\nShow details about specific commit. commit_hash must be a valid commit hash e.g 92323bc7dcdef\n\n\u003cbr/\u003e\n\n```\ngit diff\n```\n\nShow changes not staged yet. difference between staging area and working area\n\n\u003cbr/\u003e\n\n```\ngit diff –stage\n```\n\nShow changes which are staged already. Changes between staging area and commit area\n\n\u003cbr/\u003e\n\n```\ngit diff fix_branch\n```\n\nCompares the last commit of the branch you’re on and the last commit on the `fix_branch`\n\n\u003cbr/\u003e\n\n```\ngit diff --check\n```\n\nIdentifies whitespaces errors. Extra whitespaces in a file\n\n\u003cbr/\u003e\n\n```\ngit diff-tree -r commit_hash\n```\n\nList of files that has been modified in that commit hash\n\n\u003cbr/\u003e\n\n```\ngit checkout commit_hash\n```\n\nThis will will move you to the `commit_hash` where you can view your project as it was at that particular\ncommit. You can create new branch from here by passing `git branch branch_name`. \nTo go back to original state use: `git checkout branch_name`\n\n\u003cbr/\u003e\n\n```\ngit reset HEAD\n```\n\nUnstage a file without changing in it working directory. Roll back `git add` without touching\nchanges. Move commit pointer to HEAD but doesn't change files in working directory. HEAD = last commit\n\n\u003cbr/\u003e\n\n```\ngit reset –hard HEAD\n```\n\nMove pointer to last commit and change staged files back to last commit state as well.\n\n\u003cbr/\u003e\n\n```\ngit reset –hard HEAD~\n```\n\n~ = tilde\n~ = number of parents\n\n\u003cbr/\u003e\n\n```\ngit reset –hard HEAD~~ == git reset –hard HEAD~2\n```\n\nReset to 2 parents of the last commit\n\n\u003cbr/\u003e\n\n```\ngit reset HEAD file\n```\n\nReset file to last commit. same tilde(~) can be applied here.\n\n\u003cbr/\u003e\n\n```\ngit checkout -- file\n```\n\nRemove changes from a file in working directory which is not staged yet. Roll back file to its last commit\n`reset` is used to roll back committed files. \n`rm` or `--cached`` is used to roll back staging area files.\n`checkout --` is used to roll back files in working directory.\n\n\u003cbr/\u003e\n\n```\ngit stash\n```\nRecord the current state of the working directory and staging area. The command saves your local modifications away and \nreverts the working directory to match the HEAD commit.\n\n\u003cbr/\u003e\n\n```\ngit stash apply\n```\n\nBrings back stashed changes (working directory and staging area) on the top of HEAD\n\n\u003cbr/\u003e\n\n```\ngit stash drop\n```\n\nRemove stash back once you are done.\n\n\u003cbr/\u003e\n\n```\ngit remote show origin\n```\n\nShow details about `origin`\n\n\u003cbr/\u003e\n\n```\ngit ls-remote\n```\n\nList all remote branches\n\n\u003cbr/\u003e\n\n```\ngit remote add REMOTE_NAME REMOTE_URL\n```\n\nAdd remote url to the current working git repo\n\n\u003cbr/\u003e\n\n```\ngit remote set-url REMOTE_NAME\n```\n\nUpdate remote branch url\n\n\u003cbr/\u003e\n\n```\ngit checkout -b fix origin/test\n```\n\nCreate, Pull and Rename remote branch `test` to `fix` (local)\n\n\u003cbr/\u003e\n\n```\ngit checkout test\n```\n\nPull and switch to `test` branch If exist locally or remote\n\n\u003cbr/\u003e\n\n```\ngit branch fix\ngit checkout fix\ngit branch -u origin/test\n```\n\nCreate branch `fix`\nswitch to branch `fix`\nset upstream of `fix` branch to `origin/test` to track `remote/test`. \n\nAbove commands are equal to below\n\n\u003cbr/\u003e\n\n```\ngit checkout -b fix origin/test \n```\n\n`-u === --set-upstream-`\n\n\u003cbr/\u003e\n\n```\ngit branch -v\n```\n\nList all branches with last commit hash, commit message and * on active branche.\n\n\u003cbr/\u003e\n\n```\ngit branch -vv\n```\n\nList all branches with last commit hash, commit message, * on active branch and remote up-stream branch\n\n\u003cbr/\u003e\n\n```\ngit branch -m old_name new_name\n```\n\nRename local branch name\n\n\u003cbr/\u003e\n\n```\ngit branch -m new_name\n```\n\nRename local branch name if you are on current branch\n\n\u003cbr/\u003e\n\n```\ngit push origin –delete test\n```\n\nDelete `test` branch from remote repository\n\n\u003cbr/\u003e\n\n```\ngit merge fix_branch\n```\n\nThis will either just fast forward and move pointer to last commit OR create a merge commit and move pointer to that commit, \ndepending whether HEAD of current branch is parent of last commit (of fix_branch) or not.\n`git merge –ff fix_branch === git merge fix_branch`\n\n\u003cbr/\u003e\n\n```\ngit merge –no-ff fix_branch\n```\n\nCreate a new merge commit and move pointer to that whether HEAD of current branch is parent of last commit of fix_branch or not.\nThe `--no-ff` option ensures that a fast forward merge will not happen, and that a new commit object will always be created \neven if git would normally fast forward.\n\n\u003cbr/\u003e\n\n```\ngit merge –ff-only fix_branch\n```\n\nThis will check if fast forward is possible then will do it otherwise will abort saying fast forward not possible I.e if HEAD \nof current branch is not parent of last commit of `fix_branch`\n\n\u003cbr/\u003e\n\n```\ngit checkout –ours conflicted_file\n```\n\nKeep current branch changes and remove other branch's changes from file having conflicts\n\n\u003cbr/\u003e\n\n```\ngit checkout –theirs conflicted_file\n```\n\nRemove current branch changes and keep other branch's changes from file having conflicts\n\n\u003cbr/\u003e\n\n```\ngit cherry- pick commit_hash\n```\n\nClone a commit from other branch, to current branch on the top of HEAD and move pointer to it.\n\n\u003cbr/\u003e\n\n```\ngit revert commit_hash\n```\n\nInverse of `cherry-pick`. Pick that commit, revert changes in that commit, create a new commit and put those changed in new commit\n\n\u003cbr/\u003e\n\n```\ngit rebase -i HEAD~2\n```\n\nSquash last 2 commits into single commit\n\n\u003cbr/\u003e\n\n```\ngit tag\n```\n\n`tag` is like branch but don't move like branch. Tags do push with push commands. Can't be changed once created.\nlightweight tag is simple pointer to a commit.\nannotated tag is new commit pointing to a commit with details notes\n\n\u003cbr/\u003e\n\n```\ngit blame file\n```\n\nFor every line of file, it shows who changed it last time\n\n\u003cbr/\u003e\n\n[Git Interview Questions 1](https://www.toptal.com/git/interview-questions)\n\n\u003cbr/\u003e\n\n[Git Interview Questions 2](https://mindmajix.com/git-interview-questions)\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbuildwithlal%2Fgit-cheatsheet","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbuildwithlal%2Fgit-cheatsheet","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbuildwithlal%2Fgit-cheatsheet/lists"}