How to update/sync my repository master on github with the original master

Asked

Viewed 42,348 times

6

Using the command line, how can I update/sync my master with the original master from where I did the fork.

What are the different ways and their options, what is best, and how history is affected/recorded.

2 answers

12


What I usually do is:

First, I do a Github source project sketch (ex.: https://github.com/gatein/gatein-portal)

Then, a clone of my Github repository on my machine:

$ git clone [email protected]:jpkrohling/gatein-portal.git

At this point, you have a remote called "origin". Then add another, called "upstream", that points to the original:

$ git remote add upstream [email protected]:gatein/gatein-portal.git

From time to time, Sincronize:

$ git checkout master
$ git fetch upstream
$ git rebase upstream/master

After rebasing up, my master local looks exactly like the upstream master, needing only to update the github version:

$ git push origin master

I have a habit of working only on topics (ie: every new branch, a new branch). When I finish the job, I send this branch to github:

$ git push 

So, from github itself, I do a Pull Request from the commits in the branch to the upstream master. My master never directly receives my commits, which makes synchronization easier, since I consider the master as a starting point for any new Eature. When my branch commits are accepted upstream/master, they arrive in my master at the next sync.

  • Very good answer, it helped me a lot.

3

You can use the Hub, To execute a pull request just use the command:

git pull-request [-f] [-m MESSAGE|-F FILE|-i ISSUE|ISSUE-URL] [-bBASE] [-h HEAD]

Source: pull-request manpage:


You can also use the Github CLI

ghi pull-request [user] [branch]

Or, using the Github Gem:

gh pull-request [user] [branch]

Browser other questions tagged

You are not signed in. Login or sign up in order to post.