0

Suppose i forked a repo from Github now iam having 2 project sources one is the main master branch in owner repository and other is my master branch in my fork.

Now i got a problem like this.

Suppose in my project there is a file Readme with the code like this

Topics to completed

- [ ] Introduction
- [ ] [The Evolution of topic name(video)]
- [ ] [Background story]
- [ ] [Improvements]
- [ ] [Problems]
- [ ] [COnclusion]

So i have forked my repo and after completion of each topic i would mark a X and save the file in my local repo like this.

- [X] Introduction
- [X] [The Evolution of topic name(video)]
- [ ] [Background story]
- [ ] [Improvements]
- [ ] [Problems]
- [ ] [COnclusion]

Upto to here no problem was there,but real problem was during the completion of two topics the original master have few more topics to the Readme file and it looks like this now.

Topics to completed

- [ ] Introduction
- [ ] [The Evolution of topic name(video)]
- [ ] [Background story]
- [ ] [New topics -1]
- [ ] [New topics -2]
- [ ] [New topics -3]
- [ ] [Improvements]
- [ ] [Problems]
- [ ] [COnclusion]

So now i wanted to update the links and this commands will not use because my previous markings will be lost when i execute git fetch upstream and git pull upstream master.

Version of Readme file i want in my local repo is in this format.

Topics to completed

- [X] Introduction
- [X] [The Evolution of topic name(video)]
- [ ] [Background story]
- [ ] [New topics -1]
- [ ] [New topics -2]
- [ ] [New topics -3]
- [ ] [Improvements]
- [ ] [Problems]
- [ ] [COnclusion]

Please help.

SaiKiran
  • 6,244
  • 11
  • 43
  • 76

1 Answers1

2

Beside the fact you should make any evolution in a dedicated feature branch, you should not pull directly (that merges upstream/master into your master)

You should pull --rebase (which replays your local commits on top of the updated upstream/master), and then git push --force back to your fork.

You should get back your markers after re-applying your commits in the updated README.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • After reading your answer got an idea of rebasing. But how this works in my case .Can you explain with the context of above readme file. – SaiKiran Oct 08 '16 at 18:05
  • 1
    @SaiKiran As I said, simply try `git pull --rebase` on your branch `master`, instead of `git pull`. – VonC Oct 08 '16 at 18:08
  • Worked,Please change typo in your answer `---force` to `--force` . – SaiKiran Oct 08 '16 at 18:15
  • @SaiKiran Sure, typo fixed. – VonC Oct 08 '16 at 18:18
  • If the original repo gets updates will it be reflected in my fork master ? – SaiKiran Oct 08 '16 at 18:19
  • 1
    @SaiKiran yes, because your local branch would have been rebased on top of the updated upstream branch (meaning on top of the updates from the original repo). Once you force push that local branch back to your fork, your fork will include those same updates. – VonC Oct 08 '16 at 18:19
  • I have made a features branch and made my changes and i have merged into the master branch then i executed `git pull --rebase` and then i pushed it to the GIthub. No problem upto here.But now after few days the original repo got updated and it is showing me `This branch is 7 commits ahead, 8 commits behind jwasham:master.` .But i executed `git pull --rebase ` command then to my surprise it gave me `$ Current branch master is up to date.` . Where i went wrong? – SaiKiran Oct 10 '16 at 10:18
  • Those 7 commits ahead are my commits on my fork – SaiKiran Oct 10 '16 at 10:18
  • "This branch is 7 commits ahead, 8 commits behind jwasham:master": Is "This branch" your own local master or your own local feature branch? – VonC Oct 10 '16 at 12:22
  • It is my local master link here https://github.com/uppusaikiran/google-interview-university – SaiKiran Oct 10 '16 at 12:39
  • @SaiKiran more generally, when you work on a PR, you never touch the master branch (or any other branch common with the original repo): you only fetch, and then you rebase your feature branch on top of origin/master. – VonC Oct 10 '16 at 12:40
  • i got this all wrong , i have merged and started rebasing which is all wrong.I will need to work with new fork. – SaiKiran Oct 10 '16 at 12:44
  • @SaiKiran yes, that will be easier. And read http://stackoverflow.com/a/14681796/6309 ;) – VonC Oct 10 '16 at 12:47