John Mahoney

local branch on git

How to add new features using a branch.

Note that this is all local - there is no interaction with a central repository. I will write another tutorial for now to do all of the below while keeping the process synced with the central repository.

First create a new branch in which to create your cool new function.

git checkout -b coolfunctionbranch

This creates the new branch and switches to it in one command.

Have a look at which branches exist (locally) and which one you are on (starred).

git branch

Now, in your new branch, write the cool new function.

nano usecoolfunction.py
<write this script>

Check to see that this new file exists and is untracked.

git status

Add or “stage” this new file.

git add usecoolfunction.py

Finally, we commit this change, moving it from the staging area to the branch.

git commit -am "new script for extended awesomeness"

Now your branch ‘coolfunctionbranch’ is ahead of your branch ‘master’. That is, master does not have this cool new function. Assuming that everything is working as desired on the coolfunctionbranch, we want to merge this new feature back into the master.

First switch to the master branch.

git checkout master

Then merge.

git merge coolfunctionbranch

You should see something like:

Updating 215b718..8386e38
Fast-forward
usecoolfunction.py | 7 +++++++
1 file changed, 7 insertions(+)
create mode 100644 usecoolfunction.py

Now you can get rid of the unnecessary branch

git branch -d coolfunctionbranch

Success!

See also link