Keeping a fork up to date

1. Clone your fork:

git clone

2. Add remote from original repository in your forked repository:

cd into/cloned/fork-repo
git remote add upstream git://
git fetch upstream

3. Updating your fork from original repo to keep up with their changes:

git pull upstream master

4. Push change to fork repo

git push origin master





Fork git public to private

First, duplicate the repo as others said (details here):

Create a new repo (let’s call it private-repo) via the Github UI. Then:

git clone --bare
cd public-repo.git
git push --mirror
cd ..
rm -rf public-repo.git

Clone the private repo so you can work on it:

git clone
cd private-repo
make some changes
git commit
git push origin master

To pull new hotness from the public repo:

cd private-repo
git remote add public
git pull public master # Creates a merge commit
git push origin master

Your private repo now has the latest code from the public repo plus your changes.

Git Branch

Create the branch on your local machine and switch in this branch :

$ git checkout -b [name_of_your_new_branch]

Change working branch :

$ git checkout [name_of_your_new_branch]

$ git push origin [name_of_your_new_branch]

When you want to commit something in your branch, be sure to be in your branch.

You can see all branches created by using :

$ git branch

Which will show :

* approval_messages

Add a new remote for your branch :

$ git remote add [name_of_your_remote]

Push changes from your commit into your branch :

$ git push [name_of_your_new_remote] [name_of_your_branch]

Update your branch when the original branch from official repository has been updated :

$ git fetch [name_of_your_remote]

Then you need to apply to merge changes, if your branch is derivated from develop you need to do :

$ git merge [name_of_your_remote]/develop

Delete a branch on your local filesystem :

$ git branch -d [name_of_your_new_branch]

To force the deletion of local branch on your filesystem :

$ git branch -D [name_of_your_new_branch]

Delete the branch on github :

$ git push origin :[name_of_your_new_branch]

The only difference is the : to say delete, you can do it too by using github interface to remove branch :

If you want to change default branch, it’s so easy with github, in your fork go into Admin and in the drop-down list default branch choose what you want.

Git Delete Commit

1. Use git reset to go back to previous commit

git reset --hard HEAD~1    <-- go back one commit before HEAD

git reset --hard <sha1-commit-id> <-- go back to a specific commit

2. Check current commit by using git log

git log --oneline --decorate --color --graph

3. Do force push to git rid of everything above your current commit

git push origin HEAD --force