-
Notifications
You must be signed in to change notification settings - Fork 20
HowTo | Git and GitHub
ML-TANGO edited this page Oct 29, 2022
·
1 revision
- Hello World
- Setup Git
- Create repo
- Fork a repo
- GitHub Flow
- Contibuting to projects
- Be social
- Communicating on GitHub
- GitHub glossary
- Git cheatshet
- Learning resources
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.
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:
- Checkout to the branch where you want to copy the file.
git checkout feature/A
- Once you are on the correct branch, copy the file.
git checkout feature/B -- utils.js
-
Use the git status command to ensure that the file has been copied.
-
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.
👉Note
- This page might contain some wide rendered images. If you want to see the whole contents with wider page, please use Wide GitHub extension of Chrome.
- If you are experiencing the error on rendered images due to the low-bandwith Internet delay, please use F5 function key for refreshing current page.