Git pulling a branch from another repository?

后端 未结 2 757
没有蜡笔的小新
没有蜡笔的小新 2021-01-29 18:39

I have a local git repository which is a clone of a repository on github. Someone has forked the repository and made changes in a new branch on a new repository. I want to move

相关标签:
2条回答
  • 2021-01-29 19:11

    You need to make sure that git status shows that no unstaged changes exist in your local repository.
    You can do this by first stashing your local changes and than pulling that branch. Afterward you can apply your stash.


    If you want to re-create the branch structure of the fork in your local repository, you can do the following:

    git remote add fork <url of fork>
    git fetch fork
    git checkout -b fork_branch fork/<branch>
    

    This will create the local branch fork_branch with the same history like <branch> in the fork, i.e. fork_branch will branch off of your master where <branch> does in the fork. Additionally, your local branch will now track that branch in the fork, so you can easily pull in new changes committed in the fork.

    I think you still need to make sure beforehand that your working copy doesn't contain any changes.

    0 讨论(0)
  • 2021-01-29 19:30

    Method without adding remote.

    git checkout --orphan fork_branch
    git reset --hard
    git pull <url of fork> <branch>
    
    0 讨论(0)
提交回复
热议问题