Reputation: 1187
I work on local branches and push local branches to my forked repo and then do a pull request on origin. Just wanted to learn good Github Practices.
When I push my local branch to forked repo on Github. I want to make sure that my local branch is up to date with the remote origin. What is a good way to do this ? DO any of the below two work ? what is the difference between the two ? when the rebase can fail ?Or any better soln?
$git branch
master
*my_branch
$git commit -am "committed"
$git fetch origin
$git rebase origin/master
$git push
$git commit -am "committed"
$git pull --rebase
$git push
Upvotes: 0
Views: 334
Reputation: 2228
I think it is good idea to have your local master branch to be equal to origin/master and when you desire to merge the local master with your local my_branch or to able to see the diffs or some specific files and so on.
This way you will have kind of complete control over both the original code and your code. So assuming my_branch is the active one:
$git commit -am "committed"
$git checkout master
$git pull origin master
$git checkout my_branch
$git merge master
Instead of merge at the last step you can do diff or checkout only specific files from the master.
Upvotes: 1
Reputation: 2785
To keep your Fork in sync with the original ("root") repository you forked from and its master branch:
git remote add root <url-of-root-repository>
git pull root master
To ensure your local commits are in sync with your Fork on GitHub and appl local-only commits on top of any remote changes, pull with the rebase option:
git pull --rebase
Then you can push to your fork with all root repository updates on your fork, and your own commits on top.
git push
Upvotes: 0