Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jcaraballo/1982605 to your computer and use it in GitHub Desktop.
Save jcaraballo/1982605 to your computer and use it in GitHub Desktop.
How to fork a github repository in bitbucket

#Create bitbucket branch

##Create local branch

$ git checkout -b sync
Switched to a new branch 'sync'
$ git branch
  master
* sync

##Add remote

$ git remote add bb [email protected]:jcaraballo/test.git
$ git remote -v
bb	[email protected]:jcaraballo/test.git (fetch)
bb	[email protected]:jcaraballo/test.git (push)
origin	[email protected]:jcaraballo/test.git (fetch)
origin	[email protected]:jcaraballo/test.git (push)

##Push to bitbucket remote (in order to create the remote branch)

$ git push -u bb sync
Counting objects: 3, done.
Writing objects: 100% (3/3), 219 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
remote: bb/acl: jcaraballo is allowed. accepted payload.
To [email protected]:jcaraballo/test.git
 * [new branch]      sync -> sync
Branch sync set up to track remote branch sync from bb.

#Commit some stuff to the branch in bitbucket

##Do some changes in branch

$ git status
# On branch sync
nothing to commit (working directory clean)
$ touch README2
$ git add README2
$ git commit -m '2nd README'
[sync 9b22c80] 2nd README
 0 files changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 README2
$ git status
# On branch sync
# Your branch is ahead of 'bb/sync' by 1 commit.
#
nothing to commit (working directory clean)

##Push changes to bitbucket remote

$ git push
Counting objects: 3, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (2/2), 248 bytes, done.
Total 2 (delta 0), reused 0 (delta 0)
remote: bb/acl: jcaraballo is allowed. accepted payload.
To [email protected]:jcaraballo/test.git
   358cdf5..9b22c80  sync -> sync

##Do some more changes in branch sync

$ touch README3 README4
$ git add README3 README4
$ git commit -m 'READMEeees! READMEees!'
[sync f24ff03] READMEeees! READMEees!
 0 files changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 README3
 create mode 100644 README4

##Push to bitbucket

$ git push
Counting objects: 3, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (2/2), 261 bytes, done.
Total 2 (delta 0), reused 0 (delta 0)
remote: bb/acl: jcaraballo is allowed. accepted payload.
To [email protected]:jcaraballo/test.git
   9b22c80..f24ff03  sync -> sync

#Merge back into github ##Change to (local) master branch

$ git branch
  master
* sync
$ git checkout master
Switched to branch 'master'
$ git branch
* master
  sync

##Check there are no new changes in the remote

$ git pull
Already up-to-date.

##Merge (still locally) changes from sync into master

$ git merge sync
Updating 358cdf5..f24ff03
Fast-forward
 0 files changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 README2
 create mode 100644 README3
 create mode 100644 README4
$ git status
# On branch master
# Your branch is ahead of 'origin/master' by 2 commits.
#
nothing to commit (working directory clean)

##Push to origin/master at github

$ git push
Counting objects: 5, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (4/4), done.
Writing objects: 100% (4/4), 440 bytes, done.
Total 4 (delta 1), reused 0 (delta 0)
To [email protected]:jcaraballo/test.git
   358cdf5..f24ff03  master -> master
@daithi-coombes
Copy link

wow - two oss front ends on practically the same infrastructure - surely there is a simpler way. Excellent gist btw - thanks.

@ianwesty
Copy link

Thank you!

@nileshpanchal973githubcom

Really Helpful !!!!!!!!

@bfattori
Copy link

Just what I needed

@danystatic
Copy link

Thank you, really well done

@kehollin
Copy link

So no direct GUI support ala GitHub's Forks and Pull Requests?

@m3doune
Copy link

m3doune commented Dec 14, 2016

Thank you

@tudor-berariu
Copy link

Thanks! Very useful!

@thiagoaraujo84
Copy link

In Bitbucket, go to Settings > Security > Connected Accounts. Link your GitHub account with Bitbucket and choose repos to import.

@spyoungtech
Copy link

spyoungtech commented Aug 31, 2017

What would be nice is to have an architecture that would let you seamlessly keep them in sync. Maybe scripts or git aliases. IE, actions in one branch would seamlessly also be applied to the other branch. Not sure if that's a particularly useful or good idea. 🤔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment