dimatura
dimatura

Reputation: 1250

Saving changes in a remote branch in Git

I'm using Git for my personal projects with a remote repository hosted in assembla.com. I'm used to a simple svn-like workflow, but now I'm trying to do something that (I think) should be relatively simple but the git documentation has not helped me achieve it so far.

This is the situation. I made a bunch of changes in my local master branch, and committed them. Now I realize that my changes are not absolutely necessary and rather detrimental to performance, but may be useful/necessary in the future. So I want to revert the previous state, while somehow keeping these changes stored somewhere. Of course, git reset --hard won't do because it will erase my changes permanently.

I'm not sure this is the correct solution, but I'm thinking of making a branch with these changes, but I can't quite figure out the correct sequence of commands to do so. Note that I want to keep track of these changes in the remote repository, not just my local repository, since I work from different computers.

I'll be grateful for any ideas on how to do this, whether they involve remote branches or not.

Upvotes: 2

Views: 2080

Answers (3)

Frank V
Frank V

Reputation: 25419

I don't now git specifically, but I use Mercurial. If I ran in to this situation with Mercurial, I'd commit it marking it as a branch (somehow, someway) and then check out the revision desired.

On my next commit, Mercurial would create a new head revision. I know this is general, but I had the idea so I shared it.

Git and Mercurial are similar so I think the ideas should work for you... (Please Note there are terminology differences and I may not be using the right terms)

Note: It appears that others have since posted git specific directions doing sort of what I was describing.

Upvotes: 0

CB Bailey
CB Bailey

Reputation: 791899

The simplest thing to is to make a new branch containing your current state. You can then push that to the remote master and reset your master branch back to position of the remote master.

E.g.

git branch side-lined

git push origin side-lined

git reset --hard origin/master

Upvotes: 1

Cascabel
Cascabel

Reputation: 496912

You want to create a branch at your current HEAD:

git branch possibly-useful-stuff

and then reset your master branch back to where it belongs, probably one of these:

git reset --hard origin/master  # the remote branch
git reset --hard master~<n>     # n commits before master
git reset --hard <hash>         # a specific commit

To keep track of them in the remote, you'll just need to push this branch to the remote:

git push <remote> possibly-useful-stuff

Upvotes: 3

Related Questions