Skip to content

Commit 4bcbaea

Browse files
committed
fetch and push with different repositories
closes #1173
1 parent 040233f commit 4bcbaea

File tree

2 files changed

+66
-0
lines changed

2 files changed

+66
-0
lines changed

book/06-github/sections/2-contributing.asc

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ Here's how it generally works:
4343
5. Open a Pull Request on GitHub.
4444
6. Discuss, and optionally continue committing.
4545
7. The project owner merges or closes the Pull Request.
46+
8. Put the changes back in your GitHub public repository.
4647

4748
This is basically the Integration Manager workflow covered in <<ch05-distributed-git#_integration_manager>>, but instead of using email to communicate and review changes, teams use GitHub's web based tools.
4849

@@ -417,3 +418,62 @@ This isn't technically GitHub Flavored Markdown, but it is incredibly useful. In
417418
image::images/markdown-08-drag-drop.png[Drag and drop images]
418419

419420
If you look at <<_md_drag>>, you can see a small ``Parsed as Markdown'' hint above the text area. Clicking on that will give you a full cheat sheet of everything you can do with Markdown on GitHub.
421+
422+
[[_fetch_and_push_on_different_repositories]]
423+
==== Keep your GitHub public repository up-to-date
424+
425+
Once you forked from a GitHub repository, your forked repository lives alone and is autonomous regarding the original one.
426+
In particular, when the original repository has new commits, GitHub informs you by a message like:
427+
[source,text]
428+
----
429+
This branch is X commits behind <organization>:master.
430+
----
431+
For example:
432+
[source,text]
433+
----
434+
This branch is 5 commits behind progit:master.
435+
----
436+
437+
But your GitHub repository will never be automatically updated by GitHub; this is something that you must do yourself.
438+
Fortunately, this is very easy to do.
439+
440+
One possibility to do this requires no configuration.
441+
For example, if you forked from `https://github.com/progit/progit2.git`, you can keep your `master` branch up-to-date like this:
442+
443+
[source,console]
444+
----
445+
$ git checkout master <1>
446+
$ git pull https://github.com/progit/progit2.git <2>
447+
$ git push origin master <3>
448+
----
449+
<1> If you were on another branch, return to `master`.
450+
<2> Fetch changes from `https://github.com/progit/progit2.git` and merge them into `master`.
451+
<3> Push your `master` branch to `origin`.
452+
453+
This just works but it is a little verbose.
454+
Another possibility allows to do the same thing without the need to precise the repositories to pull from and push to.
455+
To do so, you need a few configuration:
456+
457+
[source,console]
458+
----
459+
$ git remote add progit https://github.com/progit/progit2.git <1>
460+
$ git branch --set-upstream-to=progit/master master <2>
461+
$ git config --local remote.pushDefault origin <3>
462+
----
463+
<1> Add the source repository and give it a name.
464+
Here, I have chosen to call it `progit`.
465+
<2> Set your `master` branch follow `progit`.
466+
Then your future fetches will fetch from `progit`.
467+
<3> Define the default push repository to `origin`.
468+
469+
Now you can fetch from `progit` and push to `origin` as simply as:
470+
471+
[source,console]
472+
----
473+
$ git checkout master <1>
474+
$ git pull <2>
475+
$ git push <3>
476+
----
477+
<1> If you were on another branch, return to `master`.
478+
<2> Fetch changes from `progit` and merge changes into `master`.
479+
<3> Push your `master` branch to `origin`.

book/10-git-internals/sections/refspec.asc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,12 @@ If they want Git to do that automatically each time they run `git push origin`,
120120

121121
Again, this will cause a `git push origin` to push the local `master` branch to the remote `qa/master` branch by default.
122122

123+
[NOTE]
124+
====
125+
You cannot use the refspec to fetch from one repository and push to another one.
126+
For an example to do so, refer to <<ch06-github#_fetch_and_push_on_different_repositories>>.
127+
====
128+
123129
==== Deleting References
124130

125131
You can also use the refspec to delete references from the remote server by running something like this:

0 commit comments

Comments
 (0)