Skip to content

Instantly share code, notes, and snippets.

@krlozadan
Last active June 18, 2024 12:09
Show Gist options
  • Save krlozadan/4b75255b88d7a1504e5e632cb817c3f5 to your computer and use it in GitHub Desktop.
Save krlozadan/4b75255b88d7a1504e5e632cb817c3f5 to your computer and use it in GitHub Desktop.
Pull from another repository without history using Git

Pull from another repository without history using Git

Ok, so lets contextualize ourselves

  • Let's say you have a main repo A which could be an open source project or a company project
  • Project A served as blueprint for your next project, B. So you either forked or cloned A and removed the .git folder to have a clean git history
  • You start working on project B as you would normally do

Now... at some point A changes and you want to pull those changes to B without getting the entire commit history. Maybe there's only 1 commit, maybe there's thousands.

Here's what you can do.

Open up a terminal and follow the steps:

# cd into your repo and change to the branch you want to merge the pull the changes into
$ git remote add <remote_alias> <remote_url>
$ git pull <remote_alias> <name_of_the_branch> --allow-unrelated-histories --no-tags
$ git reset HEAD

# Solve any conflicts
$ git add .
$ git commit -m "Your message here"

# Check your log to verify. You should see only the project B commits
$ git log

You could remove the added remote

$ git remote remove <remote_alias>

You can run the following command to check for any local undesired tags

$ git tag
$ git tag --delete <tag_name>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment