How to Copy file or folder from one branch to another in Git

Sometimes we may want to copy just one or two files from dev branch without merging the whole branch with master branch.

Below commands will do the same for us.(assuming you are in another branch than dev)

Copy One or two files from one branch to other.

git checkout dev -- path/to/your/file.

Copy folder from one branch to other.

git checkout dev -- path/to/your/folder

Copy files and folder from commit hash of another branch.

git checkout <commit_hash> <relative_path_to_file_or_dir>