Code Monkey home page Code Monkey logo

git-tips-and-tricks's Introduction

Git Tips & Tricks

How to split code from a repository into a new one and only keep relevant history

Expanded from these instructions.

The Git-filter-repo tool.

  1. Follow these instructions and download the git-filter-repo script and put it somewhere on your machine - also make sure you have Python installed.

  2. Create a new branch in the repo you want to move

  3. Make a fresh clone of the repo from this branch (a fresh clone is required for the git-filter-repo tool):

    git clone --single-branch --branch {{BRANCHNAME}} {{ORIGINAL-REPO-ADDRESS}}
    
  4. Figure out what folders & files that need to be moved to the new repo

    Any folders will be automatically added if you move a file in that folder

  5. Open the script in the root of this repo and add the path(s) from the root of the cloned repo

  6. CD into the cloned repo and run the script from inside it:

    .\{{RELATIVE-PATH-TO-UTILITY-SCRIPT}} {{PATH-TO-GIT-FILTER-REPO-SCRIPT}}
    

    For example:

    .\..\GitMove-MultiPath.ps1 C:\Users\my-user\source\repos\test\git-filter-repo
    
  7. Create a new repository

  8. Push these changes to the new remote:

    git push {{NEW-REPO-ADDRESS}} {{BRANCH-NAME}}
    
  9. Create a main branch from this branch in the new repo, delete the old branch in the new remote

  10. Set up build validation, policies, etc.

This new repository will contain only the relevant commit history for the files you chose to include

Keep in mind that the commit hashes will be changed

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)

image https://htmlpreview.github.io/?https://github.com/newren/git-filter-repo/blob/docs/html/git-filter-repo.html

Optional:

  • 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

How to duplicate a repository without forking it

If 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.

Go here for specific instructions on how to do this.

git-tips-and-tricks's People

Contributors

oscarbennich avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.