0

I just started using Git, and I come from Perforce. I am wondering if Git has a 'shelf' feature similar to Perforce.

For example: If I am currently working on a ticket in Perforce and I need to switch to another ticket, I would shelf my work in a changelist, and create another changelist for this new ticket. The work for my original ticket is shelved safely in my first changelist and is available for me to retrieve. I am wondering if I can perform a similar action in Git.

Jon
  • 8,205
  • 25
  • 87
  • 146
  • 1
    something like this? https://git-scm.com/book/en/v2/Git-Tools-Stashing-and-Cleaning – vitr Aug 22 '16 at 04:59
  • 1
    Possible duplicate of [Git: is there a functionality like the TFS shelveset?](http://stackoverflow.com/questions/15903025/git-is-there-a-functionality-like-the-tfs-shelveset) – dotnetom Aug 22 '16 at 05:01
  • 1
    Also http://stackoverflow.com/a/28008816/6309, http://stackoverflow.com/a/3070028/6309, http://stackoverflow.com/a/24117269/6309 mostly about TFS shelve feature, but the answer applies for Perforce shelf feature as well. – VonC Aug 22 '16 at 07:10

1 Answers1

4

You can do this with git branches like:

$> git checkout -b ticket-1            // creates a new branch
$> normal workflow                    
$> git commit -m "Changes" file1.txt   // commit changes

You can move to another ticket with:

$> git checkout master                     //cleans changes (stored safely with a branch)
$> git pull origin master                  // pull any latest changes - more like p4 sync
$> git checkout -b ticket-2                // new branch
$> normal workflow
$> git commit -m "New changes for ticket-2" file2.txt

Using git stash is another way. The one described above is useful in case you want to share your work via review or for a peer to checkout files etc...

nitishagar
  • 9,038
  • 3
  • 28
  • 40
  • Thanks for the nice answer, but I don't think you should **assume** the user wants to **share** work; there's nothing about that in the original question that I can see. – Bryan Pendleton Aug 26 '16 at 14:05
  • 2
    @BryanPendleton Got it. I just gave a popular use case for shelve - I am making that explicit now in the edit. – nitishagar Aug 26 '16 at 16:27