Overwrite single file in my current branch with the same file in the main branch?

Git

Git Problem Overview


Say I have two branches - master and redesign. How would I go about overwriting the file default.aspx.cs in my redesign branch with the one from master?

I found this question but it seems to go over how to revert a file back to it's previous version in the same branch. I also considered using a merge, but I don't want to merge, I want to overwrite. Suggestions?

Git Solutions


Solution 1 - Git

git checkout master path/to/default.aspx.cs

Before doing this, you probably have to : git checkout redesign

So, just git checkout FROM_BRANCH_NAME path/to/file

Solution 2 - Git

To overwrite a file in a branch from another branch, i.e, master to redesign do (when redesign is the current branch)

git checkout master ./path_to_file/default.aspx.cs

git checkout branch_name ./path_to_file/file_name.[file_extension]

To know more about the command checkout git checkout documentation

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAbe MiesslerView Question on Stackoverflow
Solution 1 - GitNepomuk PajonkView Answer on Stackoverflow
Solution 2 - GitYuvaraj AnbarasanView Answer on Stackoverflow