Git Workflow 1

  • Use the Basic GIT 

1.  Clone from an existing repo. In the example below, I cloned a forked repo to my local machine

git clone

Check the default remote repo

$ git remote
$ git remote -v
origin (fetch)
origin (push)

2. Configure remotes

When a repository is cloned, it has a default remote called origin that points to your fork on GitHub (, not the original master repo it was forked from. To keep track of the original repository, you need to add another remote named upstream.

git pull pulls in changes (git fetch + git merge) not in my local repo.

MAKE SURE that you cd to the actual directory that stores all commit messages.

cd git_dhsvm/DHSVM

git remote add upstream

git pull upstream

2. Make changes to the code

git add * or git add name.c

git commit -a -m "commit message"

3. Push the changes to the forked repo. Its not recommended to push directly to the original repo.

$ git push origin master

If the push command failed, e,g, ssh connection is rejected, follow to generate a public key that links together the github and the local machine.

4. Send a pull request to the original repo.

Use the GIT flow

1. Clone the forked repo.

git clone

2. Convert an existing local repo to the new branch structure

git flow init

Check out the branches in my local repository

git branch

3. Create a feature branch based on develop. Let’s say you want to add a login page:

git flow feature start login

This will create a new branch called feature/login, based on our develop branch and switches to it.

4. Commit away and after you finish working on the login page, simply finish it. It’ll merge feature/login back to develop and delete the feature branch.

git flow feature finish login

5. When you’re feature complete, simply start a release branch — again, based on develop — to bump the version number and fix the last bugs before releasing:

$ git flow release start v3.1.1

When you finish a release branch, it’ll merge my changes to master and back to develop, and master is simultaneously updated with develop.

6. After some final fixes, finish the release

$ git flow release finish v3.1.1

After enter this command, a editor window will pop out. Make sure that the inserted note doesn’t start with “#”

7. Push the local repo to the forked repo on GitHub.

Non-fast-forwarding problem can be solved by adding “+” before local repo branch.

$ git push origin master

More TIPS:

Normally I don’t create an empty repo but rather clone an existing one to my local machine.

If I need an empty repo, then use:

$ git init

Set default settings

$ git config --global "Ning"

$ git config --global ""

I can override my global settings for a specific repo:

$ git config --local "Ning"

$ git config --local ""

Get a listing of current repo:

$ git config -l

Fix up the previous commit message

$ git commit --amend

Remove the previous commit if not pushed to remote repo

git reset --hard HEAD~1

gitignore. Create .gitignore at my home directory named as ~/.gitignore

git config --global core.excludesfile ~/.gitignore

Check the difference in terms of file name

git whatchanged





Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s