CamJohnson26
CamJohnson26

Reputation: 1199

Use git changes from another branch

Is there a way to pull in a project from another branch so that my intelisense can see classes from that branch without modifying my current branch? I don't want to merge because the classes should be separated, I just want to pull in the changes without committing them.

Upvotes: 0

Views: 42

Answers (2)

matt123miller
matt123miller

Reputation: 191

You can perform the merge without committing the results.

Step 1: Check out the branch you want to merge INTO (I'll be using master for this example)

git checkout master

Step 2: Merge your previous branch into master with the --no-commit tag

git merge YOUR_BRANCH_NAME --no-commit

That should be sufficient. You can always run a diff at this point or before merging if you'd like to check the changes in advance.

The merge --ff tag may also be useful to you, but I've yet to use it so can't comment for certain.

When the merge resolves as a fast-forward, only update the branch pointer, without creating a merge commit. This is the default behavior.

git merge YOUR_BRANCH_NAME --no-commit --ff

https://git-scm.com/docs/git-merge#git-merge---no-commit

https://git-scm.com/docs/git-diff

Upvotes: 2

Schwern
Schwern

Reputation: 164829

Simplest thing to do is to merge the branch without committing.

git merge --no-commit thatotherbranch

Then when you're done, throw out the changes.

git reset --hard HEAD

If you want to do come experiments, you can create a temporary branch and merge things into it. Then delete it when you're done (or decide it's a good idea and keep it).

# Checkout the branch you want to work on
git checkout mybranch

# Create a new branch and check it out
git checkout -b tempbranch

# Merge in the branch with the changes you want
git merge thatotherbranch

...do whatever you like...

# Switch back to the original branch
git checkout mybranch

# Delete the temp branch
git branch -d tempbranch

Upvotes: 3

Related Questions