In TFS, I used to shelve my changes as a back-up before trying something risky or experimenting with something.
If everything went okay, I just deleted the shelve. Otherwise, I unshelved the back-up and continued.
I wasn't interested in sharing those changes with anybody.
What would be the equivalent operation in Git? I'm using VS2015 with GitHub extension, by the way.
Create a branch. Let's say you're working on master
, and you decide you want to experiment with a solution. Create a new branch:
git checkout -b my-spiffy-new-feature
Now, continue your work on the my-spiffy-new-feature
branch. What if suddenly you have a brilliant idea for a completely different solution? Just create a new branch from master
, either by running:
git checkout -b another-awesome-feature master
Or equivalently:
git checkout master
git checkout -b another-awesome-feature
In either case, do all the work on your branch. If you decide you like the feature, merge it back into the master
branch:
git checkout master
git merge my-spiffy-new-feature
You can let the branches hang around, or you can delete them if they are no longer of interest:
git branch -d my-spiffy-new-feature
Note that the above will fail if you try to delete a branch that you haven't merged into it's upstream branch (that is, the branch from which it originated); if you really want to delete a branch, even though you haven't merged it:
git branch -D another-awesome-feature
The closest thing to TFVC - Shelvesets in git I feel is stash
. As others have already mentioned that it has it's own disadvantages, one being that it is not branch specific. But still it is a good alternative depending on your requirement.
In Visual Studio 2019 - if you are looking for a quick way not to commit your changes to the current branch yet, and want to save your change for later, you can use stash like this.
In Team Explorer, you have two options for stash
:
To get your stash
back, you can right click on your stash under Stashes
section. It will give you some options:
Drop
below)Apply
and Pop
options have two sub-options:
Credit: Thomas Claudius Huber's article. Link again.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With