The git checkout
command can be used to update specific files or directories in your work tree with those of another branch (branch), without merging the entire branch.
This can be useful when working with various resource branches (FEATURE BRANCHS) or use Github Pages to generate a static design site.
The manual page of Git Checkout describes how the Git Checkout command is not useful just to switch between branches.
When <paths>
or --patch
are provided, Git Checkout no switch branches. It updates the paths nominated on the work tree from the index file or a called <tree-ish>
(usually a Commit)… the <tree-mix>
argument can be used to specify a tree-ish (ie Commit, Tag or Tree) to update the index for the paths provided before updating the work tree.
In the git, a tree-ish is a way of referring to a particular commit or tree. This can be a partial sha or the pointers of branching, remote and tag.
The syntax to use the git checkout
to update the work tree with files of a tree-ish is as follows:
git checkout [-p|--patch] [<tree-ish>] [--] <pathspec> ...
Therefore, to update the work tree with other branch files or directories, you can use the BRANCH name pointer in the git checkout
command.
git checkout <branch_name> -- <paths>;
For example, you could update a script on a white feature white being developed, “pulling” the Branch Main specific file.
# On branch main
git checkout new-branch
# On new-branch
git checkout main -- my_script.js
git commit -m "Update my_script.js from main"
It is interesting to read the git-checkout
manual page to know the other possibilities that the command brings, and to understand its versatility to deal with specific issues in its version of version and management of the source source of software development projects.
Comments