To Sync your fork from the original repository is two steps:
- Setup the upstream remote (only have to do this one time)
- check current config:
git remote -v
- add upstream remote:
git remote add upstream https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git
- check current config:
- Sync fork
git fetch upstream
git checkout master
git merge upstream/master
- You’re up-to-date locally, then update your fork,
It is a bit confusing that branches are only local by default.
A branch that is connected to a remote repository (GitHub) is called a “tracking branch”.
git clone, the
master branch is automatically created as a “tracking branch” with the GitHub repository as the “upstream branch”.
However, git knows about the other branches, but does not automatically create them locally.
Furthermore, after you create a new branch locally, and you want to push it to GitHub, you will need to add a remote.
To get information about all your remotes,
git remote show origin lists everything tracked locally and how it lines up with your remotes.
Use a remote “tracking branch” locally:
- Clone the repo,
git clone https://github.com/user/repository.git
git branchwill display only the local branches, i.e.
*masterif you just cloned it.
git branch -ato see all branches, including remotes, i.e. git knows about the other branches, it just didn’t create a local version of it yet. The remote branches will be named like
- To create a local version of the remote branch,
git checkout -b branch-name origin/branch-name. Now it is there, you can push and fetch/pull as normal. (note: there is a short cut version:
git checkout --track origin/branch-name, or even shorter: if you simply
git checkout branch-namewhen there is no local branch with that name and it exactly matches a remote branch git will automatically create a local “tracking branch”)
Create a branch locally, then add to remote:
- Create and switch to a new branch,
git checkout -b branch-name. (reminder: this is a short cut combo of two commands,
git branch branch-nameand
git checkout branch-name)
- To add the branch to the remote,
git push origin branch-namewill create the remote branch and set the “upstream” for the local version. (this is a shortcut to
git branch --set-upstream-to origin branch-nameplus
Git in Classroom
- GitHub Classroom
- Why you should use GitHub: Lessons for the classroom and newsroom
- GitHub for Academics
- use Emoji in GitHub markdown, see Emoji cheat sheet