{"id":24561541,"url":"https://github.com/oscarbennich/git-tips-and-tricks","last_synced_at":"2026-05-20T15:01:59.715Z","repository":{"id":228603786,"uuid":"774449382","full_name":"OscarBennich/git-tips-and-tricks","owner":"OscarBennich","description":"Git tips \u0026 tricks","archived":false,"fork":false,"pushed_at":"2025-01-15T12:18:51.000Z","size":33,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-23T08:36:00.390Z","etag":null,"topics":["documentation","git","tips-and-tricks","tools"],"latest_commit_sha":null,"homepage":"","language":"PowerShell","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/OscarBennich.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":"2024-03-19T15:12:58.000Z","updated_at":"2025-01-15T12:18:53.000Z","dependencies_parsed_at":"2024-06-24T15:42:51.605Z","dependency_job_id":"099b83f9-7155-4fad-9820-04a85b682023","html_url":"https://github.com/OscarBennich/git-tips-and-tricks","commit_stats":null,"previous_names":["oscarbennich/git-tips-and-tricks"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OscarBennich%2Fgit-tips-and-tricks","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OscarBennich%2Fgit-tips-and-tricks/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OscarBennich%2Fgit-tips-and-tricks/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OscarBennich%2Fgit-tips-and-tricks/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/OscarBennich","download_url":"https://codeload.github.com/OscarBennich/git-tips-and-tricks/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243941566,"owners_count":20372261,"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":["documentation","git","tips-and-tricks","tools"],"created_at":"2025-01-23T08:32:22.684Z","updated_at":"2026-05-20T15:01:59.708Z","avatar_url":"https://github.com/OscarBennich.png","language":"PowerShell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Git Tips \u0026 Tricks\n\n## How to split code from a repository into a new one and only keep relevant history\n\nExpanded from [these instructions](https://docs.github.com/en/get-started/using-git/splitting-a-subfolder-out-into-a-new-repository). *[Here](https://github.com/newren/git-filter-repo) you can find the repo for the Git-filter-repo tool.*\n\n1. Follow [these instructions](https://github.com/newren/git-filter-repo/blob/main/INSTALL.md) and download the `git-filter-repo` script and put it somewhere on your machine - also make sure you have Python installed.\n2. Create a new branch in the repo you want to move\n3. Make a fresh clone of the repo from this branch (a fresh clone is required for the `git-filter-repo` tool):\n\n   ```\n   git clone --single-branch --branch {{BRANCHNAME}} {{ORIGINAL-REPO-ADDRESS}}\n   ```\n\n4. Figure out what folders \u0026 files that need to be moved to the new repo\n   \u003e Note: If you move a specific file, any folder(s) it is part of will be automatically added\n5. Open the [script](GitMove-MultiPath.ps1) in the root of this repo and add the path(s) from the root of the cloned repo to the files and folders\n   \u003e Note: Windows users should use '/' to delimit folders (**not** '\\\\')\n7. CD into the cloned repo and run the script from inside it:\n\n   ```\n   .\\{{RELATIVE-PATH-TO-UTILITY-SCRIPT}} {{PATH-TO-GIT-FILTER-REPO-SCRIPT}}\n   ```\n\n   For example:\n\n   ```\n   .\\..\\GitMove-MultiPath.ps1 C:\\Users\\my-user\\source\\repos\\test\\git-filter-repo\n   ```\n\n8. Create a new repository\n9. Push these changes to the new remote:\n\n   ```\n   git push {{NEW-REPO-ADDRESS}} {{BRANCH-NAME}}\n   ```\n\n10. Create a `main` branch from this branch in the new repo, delete the old branch in the new remote\n11. Set up build validation, policies, etc.\n\n\u003e This new repository will contain only the relevant commit history for the files you chose to include\n\u003e\n\u003e Keep in mind that the commit hashes **will be changed**\n\u003e\n\u003e Also note that renames are NOT followed, meaning that if a file has moved into the folder you are filtering out, then the commit history before the move will be gone (unless you include the previous file location too) \n\u003e \n\u003e ![image](https://github.com/OscarBennich/git-tips-and-tricks/assets/26872957/bb0c9b2f-92e7-4214-a8a5-0e96188ddfe7)\n\u003e https://htmlpreview.github.io/?https://github.com/newren/git-filter-repo/blob/docs/html/git-filter-repo.html\n\n\nOptional:\n\n- Delete the files in the old repo and push these changes to the trunk if you do not want to keep the files in both repos\n\n## How to duplicate a repository without forking it\n\nIf you want to create a new repository from the contents of an existing repository but don't want to merge your changes to the upstream in the future, you shouldn't fork it but instead _duplicate_ it.\n\nGo [here](https://docs.github.com/en/repositories/creating-and-managing-repositories/duplicating-a-repository) or [here](https://www.atlassian.com/git/tutorials/git-move-repository) for specific instructions on how to do this.\n\n## Git hooks\nSee https://git-scm.com/book/ms/v2/Customizing-Git-Git-Hooks\n\n1. Add a script that will be executed\n2. Either manually add this hook to the correct `.git/hooks` folder or execute it through a script such as this (PowerShell in this case):\n\n```ps1\n# This scripts installs a \"precommit hook\" for this repo, so that the script ./scripts/Pre-Commit.ps1 will\n# always run when the developer runs `git commit` without the `--no-verify` flag\n\nSet-StrictMode -Version 3.0\n$ErrorActionPreference = \"Stop\"\n\n$hookPath = git rev-parse --git-path hooks\n\n$sourceFile = Join-Path $PSScriptRoot pre-commit-hook\n\nWrite-Host \"Copying the hook source file to $hookPath\"\n\nCopy-Item $sourceFile $hookPath/pre-commit\n```\n\n## Using `--no-pager` and setting git `pager` settings to false\n1. `git --no-pager diff`\n2. `git config --global pager.diff false`\n3. `git config --global pager.log false`\n\n## Using `git add -p` to stage specific hunks\n\n## Wildcard search for branches\n- `git branch --list *search term*`\n\n## Editing a specific commit\n1. Get the git hash by running `git log`\n2. Double check using `git show {{HASH}}`\n3. Run `git rebase --i {{HASH}}~`\n4. Choose to edit the commit\n5. Commit your new changes\n6. Run `git rebase --continue`\n\n(copied from [this post](https://stackoverflow.com/a/1186549))\n\n## Adding message/reminder to stashed code\n- `git stash push -m 'Message goes here'`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foscarbennich%2Fgit-tips-and-tricks","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Foscarbennich%2Fgit-tips-and-tricks","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foscarbennich%2Fgit-tips-and-tricks/lists"}