a personal broken git workflow

my situation is commonly like this:

* clone openFrameworks or an ofxAddon
* make some local changes necessary for a project
* make some commits
* come back much later without touching that repo for a while, and want to pull upstream/master to get the latest version from the server
* get merge complaints
* know that its pragmatic / cleaner to abandon my old changes and just pull the community copy and make changes from there
* not be able to find any git command which will abandon all my local unstaged*+staged changes and pull hard from upstream master
* have to delete my forks on github, delete my local clones
* refork, reclone

(*getting rid of unstaged changes is the easy bit)

obviously this is ridiculous.
one alternative seems to be to immediately start my own local branch every time and make my changes there
is this the way to go?

The idea of spending a few hours picking through the merge seems much less effective than recoding as required (although keeping a copy of the old stuff would be great). Perhaps can move all my local commits into a branch, then pull on master?

yes, as soon as you modify any upstream code (i.e. oF core or addons) you should start your own branch - makes things much easier, and is the way it’s supposed to be done.

Nevertheless, to spool back to a certain commit, discarding all following modifications in the process, you use git reset --hard . then you can git pull upstream master as usual.

moving your local commits into a separate branch could be done with git rebase (not recommended if you have already pushed changes to where other people may have used them!)

during ofdev-con we put together a small list of helpful git commands http://piratepad.net/ofgitcheatsheet

i think what you’re looking for, to bring your local copy into parity with upstream, completely dropping any local changes, then pushing to your fork:

Problem You’ve done some ridiculous stuff to your local repository and want to trash everything so it’s exactly the same as upstream. One technique is to delete your repository and re-fork, but a more elegant solution is to say:

>     git reset --hard upstream/master  
>     git push origin master --force  

This will only affect files that are being tracked. So if you have any apps, for example, that aren’t being tracked then it won’t modify them.

cheers gitterbuchi!

kyle: great collection, I added it to the github git workflow wiki page.

yes @kyle. that’s the functionality i was after.
i think you told me that sometime before as well!

to note
the above doesn’t work for me now

$ git reset  upstream/master  
fatal: ambiguous argument 'upstream/master': unknown revision or path not in the  
 working tree.  
Use '--' to separate paths from revisions  

note that upstream does exist

you forgot a “–hard” ;-). should be

git reset --hard upstream/master  

ah sorry. pasted the wrong one
i tried exactly as in the forum, then a few other things to search it out (hence copied the wrong thing out of terminal)
will see if i can get the right error message when back on the pc

ah, ok. when you do, also write what you actually wanted to accomplish in the first place.

here’s a similar example of the same problem:

[elliot@snow-white ~/dev/openFrameworks/openFrameworks/addons/ofxCv(master)]$ git fetch upstream opencv-2.3  
From [https://github.com/kylemcdonald/ofxCv](https://github.com/kylemcdonald/ofxCv)  
 * branch            opencv-2.3 -> FETCH_HEAD  
[elliot@snow-white ~/dev/openFrameworks/openFrameworks/addons/ofxCv(master)]$ git reset --hard upstream/opencv-2.3  
fatal: ambiguous argument 'upstream/opencv-2.3': unknown revision or path not in the working tree.  
Use '--' to separate paths from revisions  

trying to force local to mirror upstream/opencv-2.3

you need to checkout opencv-2.3 locally before you can reset hard to the upstream opencv-2.3 (i think).

also, try running git branch -a to see that the ‘upstream/opencv-2.3’ is actually defined. i think the git fetch should have done that. but maybe you need a more generic git fetch upstream first?

cant test this now. had to go with the ‘git command’

rm -fr x  
git clone x  

i couldn’t checkout opencv-2.3 locally at the time, had issues clearing local changes (even with stash and resets)

if we could ‘fix up’ the reset command that’d be good
e.g. add another line that makes it bulletproof

what do you mean? file a bug against git itself?

hey. sorry i meant add a line in the instructions in this post

hey @elliotwoods , next time this happens could you post the output of

git remote -v  


git branch -a  

? i’m thinking two possibilities, you have a branch named upstream/opencv2.3 (ie the ‘/’ is part of the branch name), which is confusing git; or you have something fishy going on with your upstream remote.