简体   繁体   中英

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 . I have seen solutions for it over here but there are some issues for both as explained below -

  1. Add branch original to remote by using git remote add original and then pulling this remote repo. But i have got a repo with same name on remote repo that contains company logic that i wont to mess around with. So i cant use this method.
  2. Using 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.

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.

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).

If this is what you want to do, there are two options:

  • You can use eg git merge my_task_branch to merge the my_task_branch into the current branch.
  • You can use 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.

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.


Some terminology:

Repo: A repo has one .git directory. If you have two repos, they (per definition) have two different .git directories, otherwise, they are the same repo. 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.

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. First, commits are fetched from some other remote repo (this can be done separately with git fetch command). Thereafter, some branch from the remote repo is merged into the current branch ( git merge command)

Local branch vs Remote branch: You can create any number of local branches in your repo. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM