Skip to content

HowTo | Git and GitHub

ML-TANGO edited this page Oct 29, 2022 · 1 revision

Git, GitHub KB

Git Checkout Use Case Example You are working on a branch called feature/A containing a file named utils.js. You have another branch called feature/B with an updated utils.js file.

You want to checkout that file and bring it from the branch called feature/B to the branch called feature/A.

Solution 1: Use the git checkout command

The git checkout command offers a simple way to get a file or a folder from another branch.

Here is the syntax to checkout a file from another branch:


git checkout <other-branch-name> -- path/to/your/folder

Here is the process to follow:

  1. Checkout to the branch where you want to copy the file.
git checkout feature/A
  1. Once you are on the correct branch, copy the file.
git checkout feature/B -- utils.js
  1. Use the git status command to ensure that the file has been copied.

  2. Commit and push to a remote.

When using the checkout command, you can also get:

  • A folder from another branch.
  • Multiple files by specifying each one of them.

Also, note that you can get a file/folder from the stash.