I started using vscode, have two branches like main and test,after finishing the work on test branch I switch to main branch and what I want to do is to merge test branch but only to commit&push specific files/directories on main branch.Because I do not need to commit&push all files coming from test branch.Problem is that vscode does not allow me to switch to test branch if I commit&push specific files.So I have to delete the specific files I do not need on main branch and then to commit&push on main branch.I want to commit&push on main branch only successfully tested files coming from test branch.

2 Answers 2


Before you change to main, you need to run:

git stash push

in vscode - first you access the ... menu at the top of the source control window, then select stash->stash.

According to the docs, this will stash away all remaining changes after the check in on the test branch. Once you stash, you will be allowed to change over to main without vscode or git complaining.

When you switch back to test branch to continue your work, just run

git stash pop

In vscode, its the ... menu in the source control window, then stash->pop latest stash

  • we are not talking about choosing files one by one than stash from the menu right? Is it possible to only few files to merge? I mean when I merge dev to test branch, it brings all files from dev branch even though I choose to stash them one by one. what I would like to do is that simply just switch to test branch and merge only few files I want from dev branch.
    – hakkican
    Dec 27, 2021 at 7:15

@hakkican maybe this could help

git checkout branch_name path_file/path_folder

then commit the changes.

or check this link for more explanation https://stackoverflow.com/questions/449541/how-can-i-selectively-merge-or-pick-changes-from-another-branch-in-git

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.