Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save emyasnikov/51807c9890e1c5152c0d8f9873cbd8e3 to your computer and use it in GitHub Desktop.
Save emyasnikov/51807c9890e1c5152c0d8f9873cbd8e3 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