- Notifications
You must be signed in to change notification settings - Fork23
HowTo | Git and GitHub
ML-TANGO edited this pageOct 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 ExampleYou are working on a branch calledfeature/A containing a file namedutils.js
.You have another branch calledfeature/B with anupdatedutils.js
file.
You want to checkout that file and bring it from the branch calledfeature/B to the branch calledfeature/A.
Thegit 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 thegit 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 useWide 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.