We have three environments dev, stage, and prod. We have files in each branch specific to an AWS account that mentions S3 buckets and AppIds. When we upgrade from dev to stage we create a new branch from dev and copy the AWS specific files from stage to the new branch. We merge stage and the branch to complete the upgrade. I was hoping there was a git command to copy the files I need from stage into the dev branch without having to switch branches to copy/paste to maintain the AWS specific details.
Asked
Active
Viewed 49 times
0
-
1Git is about commits, not files. But you can copy any file out of any commit into the working area. Is that what you mean? – matt May 15 '22 at 20:41
-
https://stackoverflow.com/search?q=%5Bgit%5D+file+from+different+branch – phd May 15 '22 at 21:52
1 Answers
3
You can take a file from any branch into your working tree
git checkout some-branch -- some-file
That will not bring any metadata from the original branch, just the files will automagically look like the files on that branch.

eftshift0
- 26,375
- 3
- 36
- 60
-
This looks like what I need. I have the same file with the same name on the dev branch so I wonder if there will be a conflict. If it works, I can script this and get 15 minutes of my life back every day. Thanks! – Davyd Ramirez May 16 '22 at 01:18
-
No conflicts. File is not _pulled/merged/whatever-fancy_. Contents is just taken **as is** from the other branch. – eftshift0 May 16 '22 at 06:18
-
This worked perfectly. It actually removed the need for moving files to staging "git add ." for the files that were already defined in the branch. When I did a "git status" my files were already green. Excellent stuff. Build went smooth and we went saved minutes per build. Thanks again!! – Davyd Ramirez May 17 '22 at 13:31