Keep your fork in sync. with original master :
# Now, you are in your local cloned copy of original GitHub repo:
git checkout master
You wish to update master to be in sync with original GitHub repo.
# First, add github location as "remote" (1) - here *upstream* is the name provided by us:
git remote add upstream https://github.com/original-repo-from-where-you-cloned.git
# fetch all branches - see we are using name provided above :) (2)
git fetch upstream
# apply all changes from original github location to your branch and then play your changes on top
(3)
git rebase upstream/master
Now your fork is in sync with original repo :) - but only locally. You need to push the changes to get in sync.
// Check status
git status
On branch master
Your branch is ahead of 'origin/master' by 15 commits.
(use "git push" to publish your local commits)
nothing to commit, working directory clean
// Push all changes you pulled from origin/master
git push
// Now check status again
git status
On branch master
Your branch is up-to-date with 'origin/master'.
nothing to commit, working directory clean
You may check in GitHub UI, to check whether all changes are in.
=========================================================
Notes:
(1) git-remote add
Adds a remote named <name> for the repository at <url>. The command git fetch <name> can then be used to create and update remote-tracking branches <name>/<branch>.
(2) git-fetch - Download objects and refs from another repository
(3) git-rebase - Reapply commits on top of another base tip
===============================================================
How to get your local test branch to be in sync with master ?
So, lets say now your master branch is sync with *upstream* branch.
You want to make all changes you made to master to your localbranch (say testcodebranch).
So, do this:
# git co testcodebranch
# git rebase master
This way testcodebranch will be in sync with master.
It will contain all the commits from the master branch + additional commit from you will be at the TOP.
===================================================================
// To apply a simple patch
git apply <path to filename.patch>
// to apply a git formatted patch - containing git header.
git am <path_to_filename.patch>
===================================================================