git Branch Management

Overview

This articles focuses on creating a new git branch, adding some content, then pushing new branch back to the origin. In addition, it shows how delete a remote (github) and local branch.

Create a New Git Branch and Push it Back to its Remote Origin

Create New Branch

This assumes you have already cloned a repository. For example, I have already cloned mojomojo on git hub and so I have already have a master branch. It’s this master branch (trunk if you like) that I will create a new branch from:

git branch $new_branch_name

where $new_branch_name is whatever you want to name your new branch.

Change to the New Branch

After you create a new branch you can see it listed with git branch, but it won’t be the active (*) branch until you check it out:

git checkout move_node

Make Edits

You can now make edits as usual. Either by editing an existing file that came with the initial branching or add a new file.

Commit Edits

Commit edits as usual. git commit -a for tracked files (files that have been added to the index aka staging).

Push Branch Back to Remote Origin

git push origin HEAD

Delete a Branch

Remove a Remote Branch

git push origin :my_branch

Remove Local Branch

You will have to run this command from a branch different from the one you’d like to delete.

git branch -d my_branch

Pull a Remote Branch

Sitation: Assume you already have cloned a github repository into your local workspace. Suppose there are branches other than master that you are interested in.

View All Branches

In order to see all branches that are available from the origin one can:

git branch -a

Pull a Remote Branch to Local

In order to do so one can issue:

git fetch origin remote_branch:local_branch

where remote_branch and local_branch are often one and the same.

My tags:
 
Popular tags:
 
Powered by MojoMojo