{"id":18914912,"url":"https://github.com/ajayns/git-cheatsheet","last_synced_at":"2025-09-09T14:17:14.320Z","repository":{"id":109697492,"uuid":"93596715","full_name":"ajayns/git-cheatsheet","owner":"ajayns","description":"A set of basic Git commands that I use","archived":false,"fork":false,"pushed_at":"2018-06-22T06:36:23.000Z","size":10,"stargazers_count":44,"open_issues_count":0,"forks_count":6,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-04-15T09:50:07.129Z","etag":null,"topics":["git","github"],"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/ajayns.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,"zenodo":null}},"created_at":"2017-06-07T05:40:07.000Z","updated_at":"2022-08-07T12:41:37.000Z","dependencies_parsed_at":"2023-04-20T20:08:09.062Z","dependency_job_id":null,"html_url":"https://github.com/ajayns/git-cheatsheet","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ajayns/git-cheatsheet","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ajayns%2Fgit-cheatsheet","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ajayns%2Fgit-cheatsheet/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ajayns%2Fgit-cheatsheet/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ajayns%2Fgit-cheatsheet/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ajayns","download_url":"https://codeload.github.com/ajayns/git-cheatsheet/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ajayns%2Fgit-cheatsheet/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":274309249,"owners_count":25261436,"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-09T02:00:10.223Z","response_time":80,"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":["git","github"],"created_at":"2024-11-08T10:13:22.052Z","updated_at":"2025-09-09T14:17:14.312Z","avatar_url":"https://github.com/ajayns.png","language":null,"readme":"\n# Git Commands\n\nHere's a list of basic Git commands that I use daily for dev. \n\n## Clone\nStarting with the basics, this command makes a copy of the remote to the local machine.\n\n```bash\ngit clone \u003crepo:url\u003e\n```\n(The repo looks like: https://github.com/ajayns/github-cmds)\n\n## Commit and Push\nThis set of commands is used to make changes, save them and push them to the remote, better explained step by step:\n\nFirst, add the files to git\n```bash\ngit add -A\n```\n(`.` will add all files and folders, so file names in its place can be used to add files specifically)\n\nCommit the changes\n```bash\ngit commit -m 'Add commit message here'\n```\n(A commit message is a brief account of changes made, like 'Minor fixes', 'Added login component')\n\nAdd the remote to the Git repo\n```bash\ngit remote add origin \u003crepo:url\u003e\n```\n\nPush the changes to the remote\n```bash\ngit push -u origin master\n```\n(`origin` can be replaced with other remotes depending where you want to push to. `master` refers the main branch, it can be changed to whichever branch you'd like to push)\n\nPushing commits needn't be done everytime you make a commit, instead, multiple commits can be push together from local to remote.\n\n## Branch\n\nCreate a new branch from current one\n```bash\ngit branch \u003cbranch-name\u003e\n```\n\nSwitch to a branch\n```bash\ngit checkout \u003cbranch-name\u003e\n```\n\nCreate new branch and switch to it\n```bash\ngit checkout -b \u003cbranch-name\u003e\n```\n\nDelete a branch\n```bash\ngit branch -d \u003cbranch-name\u003e\n```\n\nMerge a branch to master,\n```bash\ngit checkout master\n```\n(making sure you are in the master branch)\n```bash\ngit merge \u003cbranch-name\u003e\n```\n\nFetching a branch from remote and track it locally by adding new branch to the local repo\n```bash\ngit fetch \u003cremote\u003e \u003cbranch-name\u003e:\u003clocal-branch-name\u003e\n```\n## Syncing a forked repo\nClone the remote repo to local system and the following setups will bring the local and remote repos up to date with the source repo.\n\nAdd the source remote (where you cloned from) to git, calling it upstream\n```bash\ngit remote add upstream \u003crepo:url\u003e\n```\n\nFetch all branches from upstream\n```bash\ngit fetch upstream\n```\n\nSwitch to master branch\n```bash\ngit checkout master\n```\n\nRewrite your master branch so that any commits of yours that aren't already in upstream/master are replayed on top of that other branch: \n```bash\ngit rebase upstream/master\n```\n(These same steps can be done for branches other than master also)\n\nFinally, push the repo to your forked remote to make it up to date\n```bash\ngit push -f origin master\n```\n(Use the `-f` only when first rebase)\n\n*ALT:*\n\nAdd the source remote (where you cloned from) to git, calling it upstream\n```bash\ngit remote add upstream \u003crepo:url\u003e\n```\nFetch all branches from upstream\n```bash\ngit fetch upstream\n```\nMerge by pull\n```bash\ngit pull upstream master\n```\n\n\n## Squashing commits\nSquashing previous 'n'commits into one new commit\n```bash\n// Assuming you want to squash previous 2 commits\n// HEAD~n specifies number of commits to squash\ngit reset --soft HEAD~2 \u0026\u0026 git commit -m 'New commit message here'\n```\n\nTo squash in interactive rebase mode\n```bash\ngit rebase -i HEAD~2\n```\nFollow the steps after this screen, to select and merge from terminal itself.\n\n\n## Delete Changes\nDiscards all changes made in working directory\n```bash\ngit clean -df\ngit checkout .\n```\n(`clean` is used to clear all changes made to tracked files while `checkout .` deletes all untracked files)\n\nAlternatively, to save all changes made to working directory away and revert it to match the HEAD (last) commit\n```bash\ngit stash -u\n```\n\n## Delete Branch\nLocally delete branch:\n```bash\ngit branch -D \u003cbranch-name\u003e\n```\n\nDelete remote branch:\n```bash\ngit push \u003cremote_name\u003e --delete \u003cbranch_name\u003e\n```\n\n## Remotes\nView all of the remotes\n```bash\ngit remote -v\n```\n\nAdd a new remote\n```bash\ngit remote add \u003cremote-name\u003e \u003cremote-url\u003e\n```\n\nChanging an exising remote's URL\n```bash\ngit remote set-url \u003cremote-name\u003e \u003cnew-remote-url\u003e\n```\n\n## Undo Commit\nTo undo 1 commit\n```bash\ngit reset HEAD~1\n```\n\n## Amend Commit Message\nTo change the commit message of last commit, which is not pushed\n```bash\ngit commit --amend\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fajayns%2Fgit-cheatsheet","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fajayns%2Fgit-cheatsheet","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fajayns%2Fgit-cheatsheet/lists"}