Skip to content

Instantly share code, notes, and snippets.

@pnmcosta
Last active July 4, 2022 05:31
Show Gist options
  • Save pnmcosta/0d9ff2dc4da53f2f22ea4ec05152a36f to your computer and use it in GitHub Desktop.
Save pnmcosta/0d9ff2dc4da53f2f22ea4ec05152a36f to your computer and use it in GitHub Desktop.
Git commands to fork (and rebase) from GitHub to VSTS
# START Create Fork
# Author: Pedro Maia Costa <[email protected]>
# Note: Please see Gist first comment, replace <var-name> below with your values before running.
# fork branch into vsts
cd your-project
git init .
# the target <your-repo> as origin
git remote add origin https://<your-vsts>.visualstudio.com/<your-repo-url>
# the source repo <source-repo> as upstream
git remote add upstream https://github.com/<source-repo-url>
git remote -v
git fetch upstream
# creates new local <your-new-branch> from upstream/<the-source-branch>
git checkout -b <your-new-branch> upstream/<the-source-branch>
# push <your-new-branch> and set remote tracking to origin
git push -u origin
git status
# END Create Fork
# OTHER HELPERS:
# when you want to update your current branch from <source-repo>
# use upstream <the-source-branch> to rebase your current branch
git pull --rebase upstream <the-source-branch>
# if you already have a clone of <source-repo> locally
# switch origin url to <your-repo>
git remote set-url origin https://<your-vsts>.visualstudio.com/<your-repo-url>
# and if you already have a local branch from <source-repo>
# don't forget to switch branch tracking to origin/<your-branch>
git branch -u origin/<your-branch>
# if you had some changes on one of <your-repo> branches that you want rebased from <source-repo>
# and ensure <your-branch> is then pushed just as <the-source-branch> is use the -f argument after rebase
git push -f origin <your-branch>
# list your current remotes
git remote -v
# rebase from <source-repo> updating <your-branch> mantaining your changes
git rebase -Xtheirs upstream/<the-source-branch>
@pnmcosta
Copy link
Author

pnmcosta commented Mar 13, 2018

As a recent collaborator to @totaljs I want to ensure I keep my private VSTS repository always up to date with the latest from the framework. These scripts, in a VSTS Build Definition, allow me to have a workflow where I am able to dev, test and push into the private repository without affecting the public repo whatsoever.

If I want to share my work with the founders and moderators of the platform I'm also able to push to the upstream a modified branch that includes only my changes and is properly rebased and ready to merge/PR,

Notes

  • When creating a VSTS repo do not select readme or gitignore option when so it's empty.
  • You will not be able to use Build & Release for the first synced Pull & Push, you will need to pull from the upstream and push a new local branch to origin.
  • Ensure you have the Allow scripts to access OAuth token option selected in your Agent Phase, otherwise you won't be able to push to your repository.
  • Test, test, test oh and test again ;)

Screenshots

Total.js Readme in the VSTS project home
vsts-totaljs

Commits from GitHub showing in VSTS
vsts-totaljs-commits

Nightly Rebase Build Definition
vsts-totaljs-build

Allow scripts to access OAuth token
vsts-totaljs-build-token

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