Search code examples
gitgithubtfsshelve

How do I shelve my changes of one particular folder in Git repository?


Following is the exact scenario:

Master branch in git repository is having two folders:

  • Project A
  • Project B

I have done some major changes in Project B, whereas Project A is completely untouched. Now, I dont want to commit and push the changes in Project B at this stage, because it is waiting for the review, and there may be some revisions which may take upto a few weeks. At the same time, I dont want to keep those changes on local just to make sure that I dont lose those changes on any catastrophic event.

As I have done the changes directly in Master branch, I want to shelve those changes and will commit them later on (may be after a month). No other developer is working on that project, so I am least bothered at the time of merging.

Could anyone please suggest how can I shelve those changes, or create a private branch of those changes to merge them with the master later on?

Any help on this will be much appreciated. Thank you.

P.S. - Sorry if this looked like a basic question, but I am a TFS guy, so finding it a bit difficult to get used to with Git. There I could simply do this in one or two steps :)


Solution

  • Git is a project based version control system. This means that when you commit your work in Git, you generally commit every file in the repository. So there is no distinction between your two folders with regard to this. Note that this differs from a VCS tool like Perforce or CVS, where you could version just one of these two folders.

    With regard to your problem, perhaps the easiest thing to do would be to just create a feature branch from your current work. You can try the following:

    # git checkout yourBranch if not already there
    git checkout -b my_project_b            # create a new branch from this point
    git add .                               # add your files changed
    git commit -m 'Project B latest work'   # commit your work
    

    Now you can push your new branch with Project B changes to the remote via

    git push origin my_project_b
    

    When it comes time to use this work, simply merge my_project_b into the destination branch.