Qubix
Qubix

Reputation: 4353

Update branch in git

I am working in a branch my_branch and I want to merge all updates from the develop branch into it, without deleting my non-common files (which are only in my branch). How can that be done?

EDIT: Just to be clear: I want to merge the updates from develop into my_branch, without changing anything in develop.

Upvotes: 0

Views: 47

Answers (1)

Nico Van Belle
Nico Van Belle

Reputation: 5146

When you have checked out your feature branch or working branch (my_branch), and you have some local uncommitted changes which you do not want to lose while merging the develop branch onto it, you can temporarily 'stash' them.

git stash

Stashing

Often, when you’ve been working on part of your project, things are in a messy state and you want to switch branches for a bit to work on something else. The problem is, you don’t want to do a commit of half-done work just so you can get back to this point later. The answer to this issue is the git stash command.

Stashing takes the dirty state of your working directory — that is, your modified tracked files and staged changes — and saves it on a stack of unfinished changes that you can reapply at any time.

Afterwards, when doing a git status you see that there is nothing to commit anymore. The working directory is clean again.

Then you can go ahead and merge the develop branch onto your branch.

git merge develop.

Then, apply these stashed changes back onto your branch (my_branch).

git stash apply

At no point, changes will have been made to your develop branch.

Upvotes: 1

Related Questions