On Thu, 24 Jan 2013 06:41:32 -0800 (PST)
Bryce Martin <brycekmar...@gmail.com> wrote:
> Now, I made some changes to my
> local copy and have all of the changes committed. My working copy is
> clean. I want to push it up to heroku... what I really want is for
> it to accept the push and automatically merge the changes onto the
I have no idea what that "heroku" thing is, but with plain Git, merging
never happens on the server: the history with which you're trying to
update a branch in the remote repository must be a clean successor to
the history already contained in that branch. You can look at this at
a different angle: the history already contained in the remote branch
must also be contained in the branch you're trying to push.
The rationale for this is that contrary to certain VCS systems (notably
Subversion) Git does not track changes on the per-file basis. Say, in
Subversion, you might have 10 files in your tree and commit only the
changes to 2 of them; now, unless someone managed to update those two
files before you, the server will happily accept changes just to these
two files and the resulting state of the repository will be synthetic,
that is, not existing in anyone's checkout. Git does not allow this
kind of thing to happen as you always send commits or series of commits
to the server.
> I tried to do a git push heroku master, but I get an error
> saying that they are out of sync or something like that.
This might be a typical case when someone managed to push their changes
to the same remote branch before yours. From the Git's point of view,
your local history of the branch you intend to push does not contain the
whole history of the target remote branch anymore, so you're not
allowed to push -- if you were, you would effectively throw away the
commits made by that other person and replace them with yours.
> My thought was to do a fetch/merge and merge my local into the remote
> I fetched... I would then have to push that back?
This is what you're supposed to do, yes.
> I guess I'm a little confused on how to make this happen...
In a typical setup you fetch the current state of the remote repository
and then somehow manage the history of your local branch to include the
updated history of the remote branch you intend to push to.
Suppose your remote repository is known to Git by the name "heroku" and
you want to reconcile changes in your local branch "master" with the
changes in the remote branch "master".
First, you do
$ git fetch heroku
This makes Git fetch the missing bits of history from that repository
and update the so called "remote branches" in your local repository
(yes, the naming is confusing but bear with me).
After this, the history of the remote branch "master" at the time you
did `git fetch` is available locally in the form of a branch named
"heroku/master". You might inspect it (use `gitk --all` for a start)
and see how exactly does it diverge from your work.
Now the usual appoach is to merge this remote branch in your local
branch "master", resolving any conflicts if they will occur,
$ git checkout master
$ git merge heroku/master
and then try to push the result
$ git push heroku master
Unless someone again happened to update the target branch before you,
your push will complete OK.
A shortcut operation, which combines fetching and merging is called
pulling, so you can do:
$ git checkout master
$ git pull origin master
This would fetch the missing bits of the remote branch "master" and
then try to merge them into your local branch "master".
Yet another approach is to rebase your local branch onto the updated
history of the target remote branch after fetching it. This is a
slightly more advanced topic though so let's not dive into it now.
You should probably make yourself more comfortable with the idea of
remote branches, so please read . I would also say that reading the
most of the book (dealing with client-side Git) is a must before
starting to dabble with Git seriously.
> Do I need to supply you with any more details?
Next time, please do.
Copy and paste the command you run and the error messages you get.
Copying and pasting the results of running `git remote -v` and
`git branch -a` would also make things more clear.