[英]How to pull a local repo in git?
I need to pull a local repo to my new repo.我需要将本地仓库拉到我的新仓库中。 Lets say i want to pull original
to duplicate
.可以说我想拉original
duplicate
。 I have seen solutions for it over here but there are some issues for both as explained below -我在这里看到了解决方案,但两者都存在一些问题,如下所述-
original
to remote by using git remote add original
and then pulling this remote repo.使用git remote add original
将分支original
添加到远程,然后拉取此远程存储库。 But i have got a repo with same name on remote repo that contains company logic that i wont to mess around with.但是我在远程 repo 上有一个同名的 repo,其中包含我不会弄乱的公司逻辑。 So i cant use this method.所以我不能使用这种方法。git pull --help
i found that i can pull the repo using git pull /path/to/repo's .git/file
but these both branches are of same project so they have same .git
file.使用git pull --help
我发现我可以使用git pull /path/to/repo's .git/file
但这两个分支属于同一个项目,因此它们具有相同的.git
文件。Is there any other way i can do it?我还有其他方法可以做到吗? Thanks in advance提前致谢
I think that there is a misunderstanding between the concepts repo
, branch
and remote
here.我认为这里的repo
、 branch
和remote
概念之间存在误解。
From my understanding you want to "pull a local branch into another local branch" (ie. "pull" a branch, not a repo).根据我的理解,您想“将本地分支拉入另一个本地分支”(即“拉”一个分支,而不是回购)。 pull
is normally not terminology we use for local branches (a pull
operation involves fetching something from a remote repo). pull
通常不是我们用于本地分支的术语( pull
操作涉及从远程仓库中获取一些东西)。
If this is what you want to do, there are two options:如果这是您想要做的,有两种选择:
git merge my_task_branch
to merge the my_task_branch
into the current branch.您可以使用如git merge my_task_branch
到合并my_task_branch
进当前的分支。git rebase master
to move the changes that you have made on the current branch, so that they are based on the latest change on the local master
branch.您可以使用git rebase master
来移动您在当前分支上所做的更改,以便它们基于本地master
分支上的最新更改。 Both these options will ensure that the changes on the other branch ( my_task_branch
/ master
in the examples above) are made available in the current branch.这两个选项都将确保其他分支(上面示例中的my_task_branch
/ master
)上的更改在当前分支中可用。
Some terminology:一些术语:
Repo: A repo has one .git
directory.回购:一个回购有一个.git
目录。 If you have two repos, they (per definition) have two different .git
directories, otherwise, they are the same repo.如果您有两个存储库,则它们(根据定义)有两个不同的.git
目录,否则,它们是相同的存储库。 When you are saying "both branches are of the same project, so they have the same .git
file", you mean that both branches are in the same repo.当您说“两个分支属于同一个项目,因此它们具有相同的.git
文件”时,您的意思是两个分支都在同一个 repo 中。
Branch: A repo can have multiple branches.分支:一个仓库可以有多个分支。 Each branch represents a history of changes which may be different.每个分支代表可能不同的更改历史。 You can make some changes to one branch, commmit them.您可以对一个分支进行一些更改,提交它们。 And then checkout another branch to make some other changes there.然后签出另一个分支以在那里进行一些其他更改。
Remote: A remote is a reference to another repo from/to which you can fetch/push changes.远程:远程是对另一个存储库的引用,您可以从中获取/推送更改。
Pull: A git pull
operation has two parts.拉:一个git pull
操作有两个部分。 First, commits are fetched from some other remote repo (this can be done separately with git fetch
command).首先,提交是从其他远程仓库获取的(这可以使用git fetch
命令单独完成)。 Thereafter, some branch from the remote repo is merged into the current branch ( git merge
command)此后,来自远程仓库的一些分支被合并到当前分支( git merge
命令)
Local branch vs Remote branch: You can create any number of local branches in your repo.本地分支 vs 远程分支:你可以在你的仓库中创建任意数量的本地分支。 But a local branch is different from a remote branch.但是本地分支不同于远程分支。 You can create any number of local branches without impacting the remote repo in any way.您可以创建任意数量的本地分支,而不会以任何方式影响远程仓库。 The local branches only become visible in the remote repo if you git push
those branches.如果您git push
那些分支,则本地分支仅在远程存储库中可见。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.