{"id":20698087,"url":"https://github.com/peoray/git-notes","last_synced_at":"2026-05-26T04:38:19.011Z","repository":{"id":114792891,"uuid":"155049442","full_name":"peoray/git-notes","owner":"peoray","description":"Simple snippets with brief explanation of git commands I find super-useful and use almost daily","archived":false,"fork":false,"pushed_at":"2020-04-16T22:59:37.000Z","size":11,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-17T18:55:14.378Z","etag":null,"topics":["command-line","git","git-commands"],"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/peoray.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":"2018-10-28T08:18:51.000Z","updated_at":"2020-04-16T22:59:40.000Z","dependencies_parsed_at":null,"dependency_job_id":"0a9b5641-b857-42ec-9f49-d418df301919","html_url":"https://github.com/peoray/git-notes","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/peoray%2Fgit-notes","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peoray%2Fgit-notes/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peoray%2Fgit-notes/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peoray%2Fgit-notes/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/peoray","download_url":"https://codeload.github.com/peoray/git-notes/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242967659,"owners_count":20214280,"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":["command-line","git","git-commands"],"created_at":"2024-11-17T00:22:28.012Z","updated_at":"2025-12-25T04:07:54.270Z","avatar_url":"https://github.com/peoray.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# git-notes\n\nSimple snippets with brief explanation of git commands I find super useful and use often.\n\n## Table of Content\n\n1. [How to delete a local branch](#to-delete-a-local-branch)\n\n1. [How to delete a remote branch](#to-delete-a-remote-branch)\n\n1. [How to remove remote origin from Git repository](#to-remove-remote-origin-from-git-repo)\n\n1. [How to update a Github forked repository](#to-update-a-github-forked-repository)\n\n1. [How to untrack a file by Git](#how-to-untrack-a-file-by-git)\n  \n1. [How to untrack a directory by Git](#how-to-untrack-a-directory-by-git)\n\n1. [How to delete a .git folder from your project](#to-delete-a-git-folder-from-your-project)\n\n1. [How to change a remote's URL](#to-change-a-remote-url)\n\n1. [How to force push a git repo](#to-force-push-a-git-repo)\n\n1. [How to remove files from git that has been already been deleted from disk](#remove-files-from-git-that-have-already-been-deleted-from-disk)\n\n1. [How to rename a local branch](#to-rename-a-local-git-branch)\n\n1. [How do I delete a Git branch locally and remotely?](#to-delete-a-git-branch-locally-and-remotely)\n\n---\n\n#### To delete a local branch:\n**N.B:You cannot delete the branch you are currently on.** \n\nIf you are in the same branch that you want to delete, run:\n\n`git checkout \u003canother-branch\u003e` to switch to another branch(because you can't delete a branch you are currently on)\n\nThen delete the branch you want:\n\n`git branch -d \u003cbranch-name\u003e`\n\n**NB:** If you haven't merged the branch you want to delete, you will get this error:\n\n```\nerror: The branch 'slide' is not fully merged.\nIf you are sure you want to delete it, run 'git branch -D slide'.\n```\n\nTo then force delete the branch that hasn't been merged yet:\n\n`git branch -D \u003cbranch-name\u003e`\n\n---\n\n#### To delete a remote branch:\n\n`git push --delete \u003cremote_name\u003e \u003cbranch_name\u003e`\n\n---\n#### To remove remote origin from Git repo:\nInstead of removing and re-adding, you can do this:\n\n`git remote set-url \u003corigin\u003e git://\u003cnew.url.here\u003e`\n\nIf you insist on deleting it:\n\n`git remote rm \u003corigin\u003e`\n\nTo add another remote:\n\n`git remote add \u003corigin\u003e \u003cyourRemoteUrl\u003e`\n\n---\n\n#### To update a GitHub forked repository:\n\nAdd the remote, call it \"upstream\":\n\n`git remote add \u003cupstream\u003e https://github.com/\u003cwhoever\u003e/\u003cwhatever.git\u003e`\n\nFetch all the branches of that remote into remote-tracking branches, such as upstream/master:\n\n`git fetch \u003cupstream\u003e`\n\nMake sure that you're on your master branch(or the main branch):\n\n`git checkout master`\n\nUpdating your fork from original repo to keep up with their changes:\n\n`git merge upstream/master`\n\nSee [here](https://github.com/KirstieJane/STEMMRoleModels/wiki/Syncing-your-fork-to-the-original-repository-via-the-browser) on how to update your forked repo via the browser.\n\n---\n\n#### How to untrack a file by git:\n\n`git rm --cached \u003cfile path\u003e`\n\n---\n\n#### How to untrack a directory by git:\n\nTo remove a file or folde already tracked by git, then you must first remove it (physically, file or folder must be placed out of git folder for the time), commit changes and add the file again to folder. Then git will begin ignoring it using your instruction. \n\n**Step 1:** Add the folder path to your repo's root `.gitignore` file.\n\n**Step 2:** Remove the folder from your local git tracking, but keep it on your disk.\n\n`git rm -r --cached \u003cpath_to_your_folder/\u003e`\n\n**Step 3:** Add, commit and push your changes to your git repo.\n\nThe folder will be considered \"deleted\" from Git's point of view (i.e. they are in past history, but not in the latest commit, and people pulling from this repo will get the files removed from their trees), but stay on your working directory because you've used --`cached`\n\n---\n\n#### To delete a git folder from your project:\n`rm -rf .git`\n\nThis command will remove `.git` file from the directory. \n\nTo confirm: \n\n`git status`\n\nThis will give a command of `fatal: Not a git repository (or any of the parent directories): .git`\n\n---\n\n#### To change a remote URL:\n\nList your existing remote:\n\n`git remote -v`\n\nThen to change the existing to a new one:\n\n`git remote set-url origin [URL]`\n\nTo confirm:\n\n`git remote -v`\n\n---\n\n#### To force push a git repo:\n\n`git push --force \u003corigin_name\u003e \u003cyour_branch_name\u003e`\n\n**Short flag**\nAlso note that `-f` is short for `--force`, so\n\n`git push -f \u003corigin_name\u003e \u003cyour_branch_name\u003e`\n\n---\n\n#### Remove files from git that have already been deleted from disk\n\n\nThis tells git to automatically stage tracked files -- including deleting the previously tracked files.\n\nTo stage your whole working tree:\n\n`git add -u :/`\n\nTo stage just the current path:\n\n`git add -u .`\n\n---\n\n#### To Rename a local git branch\n\nIf you're currently in the branch:\n`git branch -m \u003cnewname\u003e`\n\nIf you're in another branch:\n`git branch -m \u003coldname\u003e \u003cnewname\u003e`\n\n---\n\n#### To delete a Git branch locally and remotely\n\n**Delete Remote Branch**\n\n   ```\n    git push -d \u003cremote_name\u003e \u003cbranch_name\u003e\n    git branch -d \u003cbranch_name\u003e\n   ```\n\nNote that in most cases the remote name is origin. In such a case you'll have to use the command like so.\n\n    `git push -d origin \u003cbranch_name\u003e`\n\n**Delete Local Branch**\n\nTo delete the local branch use one of the following:\n\n```\ngit branch -d branch_name\ngit branch -D branch_nam\n```\n\n**Note:** The `-d` option is an alias for --delete, which only deletes the branch if it has already been fully merged in its upstream branch. You could also use `-D`, which is an alias for `--delete --force`, which deletes the branch \"irrespective of its merged status.\"\n\nDon't forget to do a `git fetch --all --prune` on other machines after deleting the remote branch on the server. After deleting the local branch with git branch -d and deleting the remote branch with git push origin --delete other machines may still have \"obsolete tracking branches\" (to see them do git branch -a). To get rid of these do:\n\n`git fetch --all --prune`","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpeoray%2Fgit-notes","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpeoray%2Fgit-notes","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpeoray%2Fgit-notes/lists"}