• Skip to primary navigation
  • Skip to main content
Sal Ferrarello
  • About Sal Ferrarello
  • Speaking
  • Connect
    Mastodon GitHub Twitter (inactive)
You are here: Home / Dev Tips / Get a File from Another Git Branch

Get a File from Another Git Branch

Last updated on February 7, 2019 by Sal Ferrarello

I was working on one Git branch and I wanted a file (src/Gateway.php) from another branch (sf/update-wp-cli-commands-40).

To do this, I ran the command

git checkout sf/update-wp-cli-commands-40 -- src/Gateway.php

Which added src/Gateway.php to my Git working directory. I was then able to add the file and commit it to my current branch.

From a Specific Commit

Instead of using a branch name (sf/update-wp-cli-commands-40), you can use anything that can be used to point to a single commit (e.g. a tag or a commit hash).

git checkout 8ebb9bf -- src/Gateway.php
Sal Ferrarello
Sal Ferrarello (@salcode)
Sal is a PHP developer with a focus on the WordPress platform. He is a conference speaker with a background including Piano Player, Radio DJ, Magician/Juggler, Beach Photographer, and High School Math Teacher. Sal can be found professionally at WebDevStudios, where he works as a senior backend engineer.

Share this post:

Share on TwitterShare on FacebookShare on LinkedInShare on EmailShare on Reddit
Warning! This is a draft, not a finalized post. See full draft disclosure.

Filed Under: Dev Tips, Draft, Solution Tagged With: Git

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Copyright © 2023 · Bootstrap4 Genesis on Genesis Framework · WordPress · Log in