Git download a file from master into my branch






















The references can be abbreviated in some cases, e. The -- is pointless here. Note: the additional my-branch argument winds up being treated as a directory name. When you run git fetch origin with no additional arguments, your Git performs this default action.

When you give git fetch origin additional arguments, they are refspecs , just like this fetch setting. This was helpful to me especially, since the contents of my branch were entirely different from the master branch though this is not usually the case.

Hence, the suggestions listed by others above didn't help me and I would end up getting a copy of the master even after I checked out the branch and did a git pull. Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams? Collectives on Stack Overflow. Learn more. How to download a branch with git? Ask Question. Asked 11 years, 9 months ago. Active 2 months ago. Viewed k times. I created a branch on one computer, then pushed my changes to GitHub with: git push origin branch-name Now I am on a different computer, and I want to download that branch.

So I tried: git pull origin branch-name What do I need to do to properly pull my remote branch, without overwriting existing branches? Improve this question.

Johwhite 3 3 silver badges 17 17 bronze badges. Andrew Andrew k gold badges silver badges bronze badges. Building intelligent escalation chains for modern SRE. Featured on Meta. Now live: A fully responsive profile. Reducing the weight of our footer. Linked 3. Related Hot Network Questions. Question feed. Stack Overflow works best with JavaScript enabled.

Accept all cookies Customize settings. TomaszGandor Yes, I mention that in stackoverflow. Show 23 more comments. Everything is much simpler, use git checkout for that. Dmitry Avtonomov Dmitry Avtonomov 7, 4 4 gold badges 29 29 silver badges 36 36 bronze badges.

Ask me how I know. Mymozaaa the question did not mention remotes, thus the assumption that it is a purely local repo — Dmitry Avtonomov. Will this command bring the file's history, or just the last version of the file?

There is no such a thing as "history of a file", all history information is only stored in branches. This seems to automatically stage the checked-out file. Is it possible to do the same without staging? Show 3 more comments. Philip Rego 3 3 gold badges 17 17 silver badges 31 31 bronze badges. Sarath Sarath 6 6 silver badges 4 4 bronze badges. PhilipRego This answer is correct. I'm guessing there is different capitalization or punctuation in your branch, or you only have a remote branch and not a local one.

See the git checkout doc: git-scm. Bret I found it doesn't work when the branch name has a period. I suggested an edit — Philip Rego. This is best answer. I wish this answer was the highest rated. The current highest one is very confusing and not straightforward — Russell Lego. Supplemental to VonC's and chhh's answers.

Asclepius I hate specifying long paths. Is the double dash -- between the branch name and paths optional? Honestly I don't know.

I didn't even notice that I had forgotten the double dash until you pointed this out. If you have a complex history, it becomes very hard to do correctly. Instead you could use git filter-branch. The easy way is with a --tree-filter.

You would put a copy of the file somewhere outside the work tree, then. Then filter-branch will proceed to check out each commit in your history, run the cp command to add the file to the worktree for that commit, and write a new commit with the resulting content. Then it will move branches from the old commits to the new ones. If you have tags and want them to move, too, add a --tag-name-filter argument like.



0コメント