Importing one git repo as a branch into another git repo

For historic reason we have source code for different version in different git repositories. So while Project A holds the version X of the source Project B holds version Y of the source.

Do you guys know a way to import Project B as a branch of Project A?

  • How can I print the contents of a Git object as it is stored in the .git folder?
  • How to print the contents of a pygit object in python
  • How to Pull from github and keep local file without resolving merge conflicts
  • Git repository not found
  • What is the correct way with NPM to package a BUILT version of a forked Git repository?
  • How should I set the version number between releases?
  • Thanks

  • Several urls for a submodule?
  • Git Hub GitIgnore error
  • How to commit repo A into repo B?
  • How to do a GitHub pull request
  • Git status ignore line endings / identical files / windows & linux environment / dropbox / mled
  • Update **not** the current branch (in Git)
  • 2 Solutions collect form web for “Importing one git repo as a branch into another git repo”

    This is simple with Git. You have to add project B as remote, then fetch:

    git remote add projectB git://url.to/projectB.git
    git fetch projectB
    

    I am not sure, what you mean by “git project”. In git the states of source code are described by commits (a.k.a. revisions). These are stored in repositories, but are independent of the them and can be copied between repositories freely. In fact, to work on the sources git always copies the commits to your local repository that lives in the .git directory of your working copy. Branches are just names pointing to commits.

    So if you have some branches in one repository and other branches in another repository, you can:

    1. Pull both into your local working repository:

      git remote add B git://url.to/project.B.git
      git fetch B
      
    2. Base your work on branches from B

      git checkout -b newname remotes/B/branchname
      
    3. Push the branches you got from one central repository to the other:

      git push origin remotes/B/branchname:branchname
      

      or the other way around

      git push B remotes/origin/master:othername
      

    You can omit the remotes/ prefix most of the time.

    Git Baby is a git and github fan, let's start git clone.