Skip to content

Instantly share code, notes, and snippets.

@rotimi-best
Last active June 4, 2024 08:10
Show Gist options
  • Save rotimi-best/dc51f09a373815434dd3a7d578d4648a to your computer and use it in GitHub Desktop.
Save rotimi-best/dc51f09a373815434dd3a7d578d4648a to your computer and use it in GitHub Desktop.
How to merge one folder within two branches in git

git - How to merge one folder within two branches

In my project folder I have 2 folders client and server, I only want get the changes in my server folder from master to prod branch

  1. git checkout prod - Go to the branch with the oldest changes
  2. git merge --no-commit --no-ff master - Merge with the branch with the latest changes. Read More
  3. git reset -- client* - Unstage any changes from client folder, I only want to server folder. Read More
  4. git checkout -- client* - Remove any changes from client folder, I only want to server folder.
  5. git clean -n - View all unstaged files. Read More
  6. git clean -fd - Remove all unstaged folder, if you dont want to remove all then you should add those with git add <path> and then run this command. Read More
  7. Check if you have the required changes in the prod branch
  8. git add . && git commit -m "Merge master with prod" - Stage and commit your changes in the prod branch

Credit

The inspiration for this task came from an issue I had and this article helped think in the right direction

@ChristianRM
Copy link

Thank you :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment