Skip to content

Commit

Permalink
Implement fork syncing tutorial
Browse files Browse the repository at this point in the history
  • Loading branch information
draperunner committed Aug 28, 2019
1 parent 3d34ab6 commit f3d78a8
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ So you have a mess on your hands. What sort of mess?
1: An uncommitted mess
2: I accidentally committed something
3: My Git history is ugly
4: I have a bunch of old branches I want gone
5: I want to sync my fork with the original repo
>
```

Expand Down
55 changes: 55 additions & 0 deletions git-pretty.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ async function main() {
'I accidentally committed something',
'My Git history is ugly',
'I have a bunch of old branches I want gone',
'I want to sync my fork with the original repo',
])

if (answer === '1') {
Expand Down Expand Up @@ -213,6 +214,60 @@ async function main() {
console.log('Check out https://stackoverflow.com/questions/6127328/how-can-i-delete-all-git-branches-which-have-been-merged')
return '4'
}

if (answer === '5') {
console.log('Alright! You have forked a repo a while ago, and now it\'s time to update it with the changes in the original repo.')
console.log()

const answer = await ask('Have you already configured the original repo as a remote?', [
'No',
'Yes',
'Not sure'
])

if (answer === '1') {
console.log('Let\'s set up a remote.')
printCode('git remote add upstream https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git')
console.log()
console.log('Verify that it was added by listing all remotes:')
printCode('git remote -v')
console.log()
console.log('Fetch the changes from the remote:')
printCode('git fetch upstream')
console.log()
console.log('Now checkout your local master branch')
printCode('git checkout master')
console.log()
console.log('Merge the changes from the remote into your local branch')
printCode('git merge upstream/master')
console.log()
console.log('Read GitHub\'s guide for this if you don\'t trust git-pretty: https://help.github.com/en/articles/syncing-a-fork')
return '52'
}

if (answer === '2') {
console.log('Ok then. I\'ll assume the name of your remote for the original repo is "upstream"')
console.log()
console.log('Fetch the changes from the remote:')
printCode('git fetch upstream')
console.log()
console.log('Now checkout your local master branch')
printCode('git checkout master')
console.log()
console.log('Merge the changes from the remote into your local branch')
printCode('git merge upstream/master')
console.log()
console.log('Read GitHub\'s guide for this if you don\'t trust git-pretty: https://help.github.com/en/articles/syncing-a-fork')
return '51'
}

if (answer === '3') {
console.log('Not sure? Do this:')
printCode('git remote -v')
console.log('If the original repo is in that list, that means the remote is configured.')
return '53'
}
}
}

main()

0 comments on commit f3d78a8

Please sign in to comment.