diff --git a/remotes/index.html b/remotes/index.html index d52700a..39709bd 100644 --- a/remotes/index.html +++ b/remotes/index.html @@ -262,7 +262,81 @@ From github.com:schacon/hw
Cool.
+To share the cool commits you've done with others, you need to push your
+ changes to the remote repository. To do this, you run
+ git push [alias] [branch]
which will attempt to make your [branch]
+ the new [branch] on the [alias] remote. Let's try it by initially pushing
+ our 'master' branch to the new 'github' remote we created earlier.
+$ git push github master +Counting objects: 25, done. +Delta compression using up to 2 threads. +Compressing objects: 100% (25/25), done. +Writing objects: 100% (25/25), 2.43 KiB, done. +Total 25 (delta 4), reused 0 (delta 0) +To git@github.com:schacon/hw.git + * [new branch] master -> master ++ +
Pretty easy. Now if someone clones that repository they will get exactly + what I have committed and all of it's history.
+ +What if I have a topic branch like the 'erlang' branch we created earlier + and I just want to share that? You can just push that branch instead. + +
+$ git push github erlang +Counting objects: 7, done. +Delta compression using up to 2 threads. +Compressing objects: 100% (6/6), done. +Writing objects: 100% (6/6), 652 bytes, done. +Total 6 (delta 1), reused 0 (delta 0) +To git@github.com:schacon/hw.git + * [new branch] erlang -> erlang ++ +
Now when people clone or fetch from that repository, they'll get a 'erlang' + branch they can look at and merge from. You can push any branch to any + remote repository that you have write access to in this way. If your branch + is already on the server, it will try to update it, if it is not, Git will + add it.
+ +The last major issue you run into with pushing to remote branches is the
+ case of someone pushing in the meantime. If you and another developer clone
+ at the same time, you both do commits, then she pushes and then you try to
+ push, Git will by default not allow you to overwrite her changes. Instead,
+ it basically runs git log
on the branch you're trying to push and
+ makes sure it can see the current tip of the servers branch in your pushes
+ history. If it can't see what is on the server in your history, it concludes
+ that you are out of date and will reject your push. You will rightly have to
+ fetch, merge then push again - which makes sure you take her changes into
+ account.
This is what happens when you try to push a branch to a remote branch + that has been updated in the meantime:
+ ++$ git push github master +To git@github.com:schacon/hw.git + ! [rejected] master -> master (non-fast-forward) +error: failed to push some refs to 'git@github.com:schacon/hw.git' +To prevent you from losing history, non-fast-forward updates were rejected +Merge the remote changes before pushing again. See the 'Note about +fast-forwards' section of 'git push --help' for details. ++ +
You can fix this by running git fetch github; git merge github/master
+ and then pushing again.
+
+
+ In a nutshell you run git push [alias] [branch]
to update a
+ remote repository with the changes you've made locally. It will take what your
+ [branch] looks like and push it to be [branch] on the remote, if possible. If
+ someone else has pushed since you last fetched and merged, the Git server will
+ deny your push until you are up to date.
+