{"id":21039441,"url":"https://github.com/arjunu/git-cheatsheet","last_synced_at":"2026-03-19T18:34:14.599Z","repository":{"id":81629324,"uuid":"56581054","full_name":"arjunu/git-cheatsheet","owner":"arjunu","description":null,"archived":false,"fork":false,"pushed_at":"2019-09-16T09:44:43.000Z","size":9,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-13T21:18:20.997Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/arjunu.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":"2016-04-19T08:55:21.000Z","updated_at":"2024-02-28T18:23:59.000Z","dependencies_parsed_at":null,"dependency_job_id":"85608776-2d04-47b3-950e-43a0659c16e9","html_url":"https://github.com/arjunu/git-cheatsheet","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/arjunu/git-cheatsheet","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arjunu%2Fgit-cheatsheet","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arjunu%2Fgit-cheatsheet/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arjunu%2Fgit-cheatsheet/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arjunu%2Fgit-cheatsheet/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/arjunu","download_url":"https://codeload.github.com/arjunu/git-cheatsheet/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arjunu%2Fgit-cheatsheet/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273573964,"owners_count":25129882,"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","status":"online","status_checked_at":"2025-09-04T02:00:08.968Z","response_time":61,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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-19T13:41:29.175Z","updated_at":"2026-02-12T13:18:30.923Z","avatar_url":"https://github.com/arjunu.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# Git Cheatsheet\n\n? - indicates optional arguments \u003cbr\u003e\nDangerous commands are marked with :warning:\n\n## Configure\n\n- Set username \u003cbr\u003e\n`$ git config --global user.name \"\u003cname\u003e\"`\n\n- Set email \u003cbr\u003e\n`$ git config --global user.email \"\u003cemail address\u003e\"`\n\n:information_source: Drop `--global` option to set local (repo specific) config.\n\n## Create/Clone\n\n- Create new local repo \u003cbr\u003e\n`$ git init \u003c?project-name\u003e`\n\n- Clone existing  \u003cbr\u003e\n`$ git clone \u003curl\u003e` \u003cbr\u003e\n\n- Create from existing code  \u003cbr\u003e\n`$ git init` \u003cbr\u003e\nAdd files \u0026 commit \u003cbr\u003e\n`$ git remote add origin \u003cremote\u003e` \u003cbr\u003e\n`$ git push origin master` \u003cbr\u003e\n\n## Local Changes\n\n- Add all changes for next commit \u003cbr\u003e\n`$ git add .` \u003cbr\u003e\n\n- List all new \u0026 modified files to be committed \u003cbr\u003e\n`$ git status` \u003cbr\u003e\n\n- Show unstaged changes \u003cbr\u003e\n`$ git diff` \u003cbr\u003e\n\n- Commit \u003cbr\u003e\n`$ git commit -m \"\u003cmessage\u003e\"` \u003cbr\u003e\n\n## Update\n\n- Fetch \u003cbr\u003e\n`$ git fetch` \u003cbr\u003e\n\n- Pull (fetch \u0026 merge) \u003cbr\u003e\n`$ git pull` \u003cbr\u003e\n\n- Push \u003cbr\u003e\n`$ git push \u003cremote-name\u003e \u003cbranch-name\u003e` \u003cbr\u003e\n\n## Branches\n\n- Get current branch name \u003cbr\u003e\n`$ git branch | grep \\* | cut -d ' ' -f2`\n\n- List all existing branches \u003cbr\u003e\n`$ git branch -av` \u003cbr\u003e\n\n- Create new branch \u003cbr\u003e\n`$ git branch \u003cnew-branch-name\u003e` \u003cbr\u003e\n\n- Switch to branch \u003cbr\u003e\n`$ git checkout \u003cbranch-name\u003e` \u003cbr\u003e\n\n- Carry changes to a new branch \u003cbr\u003e\n`$ git checkout -b \u003cbranch-name\u003e` \u003cbr\u003e\n\n- Merge specified branch into current branch \u003cbr\u003e\n`$ git merge \u003cbranch-name\u003e` \u003cbr\u003e\n\n- Delete branch \u003cbr\u003e\n`$ git branch -d \u003cbranch-name\u003e` \u003cbr\u003e\n\n- Delete unmerged branch \u003cbr\u003e\n`$ git branch -D \u003cbranch-name\u003e` :warning: \u003cbr\u003e \n\n- Rename branch \u003cbr\u003e\n`$ git branch -m \u003cnew-branch-name\u003e` # Rename current branch \u003cbr\u003e\n`$ git branch -m \u003cold-branch-name\u003e \u003cnew-branch-name\u003e` # Rename another branch \u003cbr\u003e\n\n- Rename remote branch (after above step) \u003ca href=\"#sources\"\u003e[2]\u003c/a\u003e \u003cbr\u003e\n`$ git push origin :old_branch`                 # Delete the old branch \u003cbr\u003e\n`$ git push --set-upstream origin new_branch`   # Push the new branch, set local branch \u003cbr\u003e\n\n- Reset branch w.r.t. master\n`$ git reset $(git merge-base master \u003cyour-branch\u003e)`\n\n## Remotes\n\n- Show all remotes \u003cbr\u003e\n`$ git remote -v` \u003cbr\u003e\n\n- Add remote \u003cbr\u003e\n`$ git remote add \u003cshortname\u003e \u003curl\u003e` \u003cbr\u003e\n\n- Show remote information \u003cbr\u003e\n`$ git remote show \u003cremote-name\u003e` \u003cbr\u003e\n\n- Rename remote shortname \u003cbr\u003e\n`$ git remote rename \u003cold-shortname\u003e \u003cnew-shortname\u003e` \u003cbr\u003e\n\n## Removing Files\n\n- Delete file from working directory and stage the deletion \u003cbr\u003e\n`$ git rm \u003cfile\u003e` \u003cbr\u003e\n\n- Remove file from version control but preserve it locally \u003cbr\u003e\n`$ git rm --cached \u003cfile\u003e` \u003cbr\u003e\n\n## History\n\n- Show all commits in reverse chronological order \u003cbr\u003e\n`$ git log` \u003cbr\u003e\n\n## Undoing\n\n- Remove uncommitted changes \u003cbr\u003e\n`$ git checkout .` :warning: # use -f for force \u003cbr\u003e\n\n- Change last commit \u003cbr\u003e\n`$ git commit --amend` \u003cbr\u003e\n\n- Undo last local commit \u003ca href=\"#sources\"\u003e[1]\u003c/a\u003e \u003cbr\u003e\n`$ git reset --soft HEAD~` # soft -- keep your changes\u003cbr\u003e\n`$ git reset --hard HEAD^` # hard -- discard changes\u003cbr\u003e\n\n- Undo last published commit \u003ca href=\"#sources\"\u003e[1]\u003c/a\u003e \u003cbr\u003e\n`$ git revert HEAD` \u003cbr\u003e\n\n- Unstage a file \u003cbr\u003e\n`$ git reset HEAD \u003cfile\u003e` \u003cbr\u003e\n\n- Unmodify a file \u003cbr\u003e\n`$ git checkout -- \u003cfile\u003e` :warning:\u003cbr\u003e\n\n- Remove untracked files \u003cbr\u003e\n`$ git clean -f` :warning:\u003cbr\u003e\n\n- Remove untracked directories \u003cbr\u003e\n`$ git clean -d` :warning:\u003cbr\u003e\n\n- Reset branch to remote  \u003cbr\u003e\n`$ git reset --hard origin/\u003cbranch-name\u003e`\n\n## Tags\n\n- Create tag \u003cbr\u003e\n`$ git tag -a \u003ctag\u003e -m \"\u003cmessage\u003e\"` \n\n- Push all tags \u003cbr\u003e\n`$ git push origin --tags`\n\n## Cleanup\n\n- Delete all local branches that no longer have a remote :warning: \u003cbr\u003e\n`$ git branch -r | awk '{print $1}' | egrep -v -f /dev/fd/0 \u003c(git branch -vv | grep origin) | awk '{print $1}' | xargs git branch -d`\n\n## Glossary\n\n#### Files\n\n- **Commited:** data is safely stored in your local database\n \n- **Modified:** you have changed the file but have not committed it to your database yet\n \n- **Staged:** you have marked a modified file in its current version to go into your next commit snapshot\n\n- **Tracked:** are files that were in the last snapshot; they can be unmodified, modified, or staged \n \n- **Untracked:** files are everything else – any files in your working directory that were not in your last snapshot and are not in your staging area\n \n#### Repository\n\n- **Remote:** Remote repositories are versions of your project that are hosted on the Internet or network somewhere\n \n- **Origin:** Default name Git gives to the server you cloned from\n\n#### Branches\n\n- **master:** name given to default branch.\n \n- **HEAD:** pointer to current branch.\n\n- **fast-forward:** is a type of merge. When you try to merge one commit with a commit that can be reached by following the first commit’s history, Git simplifies things by moving the pointer forward because there is no divergent work to merge together.\n\n- **Remote tracking branches:** are references to the state of remote branches. They act as bookmarks to remind you where the branches in your remote repositories were the last time you connected to them.\n\n- **Rebase:** another type of integrating changes (the other one being `merge`) from one branch into another by taking all the changes that were committed on one branch and replaying them on another.\n\n## Sources\n- [1]: Undo a commit and redo http://stackoverflow.com/a/927386/2251156\n- [2]: Updating your local branch's tracking reference to the new remote http://stackoverflow.com/a/16220970/2251156\n \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farjunu%2Fgit-cheatsheet","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Farjunu%2Fgit-cheatsheet","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farjunu%2Fgit-cheatsheet/lists"}