Difference between revisions of "Branching"

From Geos-chem
Jump to: navigation, search
(Use Git Gui to create a new branch)
 
(59 intermediate revisions by the same user not shown)
Line 1: Line 1:
'''''[[Using the Git GUI|Previous]] | [[Committing|Next]] | [[Guide to using Git with GEOS-Chem]] | [[Getting Started with GEOS-Chem]] | [[Main Page|GEOS-Chem Main Page]]'''''
+
'''''[[Using Git GUI|Previous]] | [[Committing|Next]] | [[Guide to using Git with GEOS-Chem]]'''''
 +
 
 +
#[[Introduction to Git]]
 +
#[[Installing Git]]
 +
#[[First-time Git setup]]
 +
#[[Cloning (i.e. downloading for the first time)]]
 +
#[[Ignoring files]]
 +
#[[Viewing the revision history]]
 +
#[[Using Git GUI]]
 +
#<span style="color:blue">'''Branching'''</span>
 +
#[[Committing]]
 +
#[[Tagging]]
 +
#[[Merging]]
 +
#[[Receiving updates (aka pulling)]]
 +
#[[Using patches to share your updates with others]]
 +
#[[Advanced Git usage]]
 +
#[[Git and Github tutorials]]
 +
 
  
 
== Overview  ==
 
== Overview  ==
Line 10: Line 27:
 
=== Use Git Gui to create a new branch ===
 
=== Use Git Gui to create a new branch ===
  
To create a new branch in the '''git gui''', go to the '''Branch/Create''' on the menu bar (or type '''CTRL-N''').
+
(1) '''Start git GUI''':
 +
 
 +
git gui &
 +
 
 +
(2) Select '''Branch/Create''' on the menu bar (or type '''CTRL-N''').
  
 
[[Image:GitGuiBranchMenu.png]]
 
[[Image:GitGuiBranchMenu.png]]
  
You will get a dialog box that prompts you for the new branch name.   
+
(3) A dialog box will appear. Type the name of the new branch and click on '''Create'''.   
 +
 
 +
NOTE: Your new branch name should adhere to the [[Viewing_the_revision_history#Branches|Gitflow nomenclature]].
  
 
[[Image:GitGuiNewBranch.png]]
 
[[Image:GitGuiNewBranch.png]]
  
The current branch name is displayed at the top left of the Git GUI, and will also be highlighted in the '''Create New Branch''' menu.  Your new branch will split off the currently checked-out branch.
+
(4) Git will automatically check out the new branch that you just created.
 
+
In the '''Create New Branch''' dialog box, type a unique branch name and then click OK.  Your new branch name should adhere to the [[Viewing_the_revision_history#Branches|Gitflow nomenclature]].  You will be automatically placed into the branch you have just created.
+
  
 
=== Use Gitk to create a new branch ===
 
=== Use Gitk to create a new branch ===
  
You can also create a new branch very quickly from the Gitk browser.  Right click on any commit, and then pick: '''Create new branch'''
+
You can also create a new branch very quickly from the [[Viewing_the_revision_history#Use_Gitk_to_see_a_graphical_display|Gitk browser]].   
  
[[Image:GitkCreateBranch.png]]
+
(1) Start gitk
  
This will pop open a dialog box that asks you to pick the name of the new branch.
+
gitk --all &
 +
 
 +
(2) Move your mouse to the name of the commit from which you would like to create a new branch.  Right-click on the name of that commit.
  
 
[[Image:GitkNewBranch.png]]
 
[[Image:GitkNewBranch.png]]
  
Your new branch name should adhere to the [[Viewing_the_revision_history#Branches|Gitflow nomenclature]].
+
(3) A context menu will appear. Select '''Create New Branch'''.
 +
 
 +
[[Image:GitKCreateBranch.png]]
 +
 
 +
(4) A dialog box will appear. Type the name for your branch and click on '''Create'''. 
 +
 
 +
Your new branch name should adhere to the [[Viewing_the_revision_history#Branches|Gitflow nomenclature]].
 +
 
 +
Git will automatically check out the new branch that you just created.
  
 
=== Create a new branch from the command line ===
 
=== Create a new branch from the command line ===
  
First, check out the branch that you wish to branch off from.  In this case, let's branch off master.
+
(1) First, check out the branch that you wish to branch off from.  In this case, let's branch off master.
  
 
  git checkout master
 
  git checkout master
  
Then type
+
(2a) If you are creating a new feature branch, then type:
  
  git branch feature/MyFeature
+
  git branch feature/NAME
  git checkout feature/MyFeature
+
  git checkout feature/NAME
  
Your new branch name should adhere to the [[Viewing_the_revision_history#Branches|Gitflow nomenclature]].
+
(2b) On the other hand, if you are creating a bugfix branch, then type:
 +
 
 +
git branch bugfix/NAME
 +
git checkout bugfix/NAME
 +
 
 +
where <tt>NAME</tt> is to be the name of the feature or bug fix that you are implementing.
  
 
--[[User:Bmy|Bob Yantosca]] ([[User talk:Bmy|talk]]) 15:25, 20 June 2019 (UTC)
 
--[[User:Bmy|Bob Yantosca]] ([[User talk:Bmy|talk]]) 15:25, 20 June 2019 (UTC)
  
== Determining which branch you are on ==
+
== Switching between (aka "checking out") branches ==
 +
 
 +
=== Check out a branch with Git GUI ===
 +
 
 +
(1) '''Start Git GUI'''.
 +
 
 +
git gui &
 +
 
 +
(2) Select the '''Branch/Checkout''' menu item.
 +
 
 +
[[Image:GitGuiCheckOut.png]]
 +
 
 +
(3) A dialog box will appear.  Click on the name of the branch you would like to check out.
 +
 
 +
[[Image:GitGuiCheckOutBox.png]]
 +
 
 +
(4) Click on '''Checkout'''.
 +
 
 +
=== Check out a branch with GitK ===
 +
 
 +
(1) '''Start Gitk'''.
 +
 
 +
gitk --all &
 +
 
 +
(2) Right-click the <span style="color:green">GREEN BOX</span> that correponds to the branch that you would like to check out.
 +
 
 +
[[Image:GitKCheckOut.png]]
 +
 
 +
(3)  A context menu will appear. Click on '''Check out this branch'''.
 +
 
 +
=== Check out a branch from the command line ===
 +
 
 +
If you are in a Git-backed code directory, and want to know what the current branch is, type:
 +
 
 +
git checkout BRANCH-NAME
 +
 
 +
If you would like to check the current branch in a different directory, use the <tt>-C</tt> option.  Type:
 +
 
 +
git -C /path/to/Code checkout BRANCH-NAME
 +
 
 +
== Determining which branch is checked out ==
 +
 
 +
You can determine which branch is currently checked-out as follows:
  
You can determine which branch you are on as follows:
 
 
{| border=1 cellspacing=0 cellpadding=5
 
{| border=1 cellspacing=0 cellpadding=5
 
|-bgcolor="#CCCCCC"
 
|-bgcolor="#CCCCCC"
 
!width="150px"|Using this:
 
!width="150px"|Using this:
!width="700px"|Follow these steps:
+
!width="850px"|Follow these steps:
  
 
|-valign="top"
 
|-valign="top"
|Git GUI
+
|[[Using Git GUI|Git GUI]]
|Look at the top left (under the Repository menu), and you will see the name of the currently-checked out branch.
+
|Look at the top left (under the Repository menu), and you will see the name the branch that is currently checked-out.
  
 
|-valign="top"
 
|-valign="top"
|Gitk
+
|[[Viewing the revision history#Use Gitk to see a graphical display|Gitk]]
|Look for the green box with the boldfaced name inside.  This indicates the current branch.  
+
|Look for the <span style="color:green">GREEN BOX</span> with the '''boldfaced name''' inside.  This indicates the branch that is currently checked-out.
  
 
|-valign="top"
 
|-valign="top"
 
|The command line
 
|The command line
 
|Type:
 
|Type:
 
 
  git branch
 
  git branch
  
and you will see all of the branches.  
+
and you will see all of the branches:  
 
   dev/12.4.0
 
   dev/12.4.0
 
  *master
 
  *master
  
The current branch will have an <tt>*</tt> in front of it.
+
The branch that is currently checked-out will have an <tt>*</tt> in front of it.
  
 +
NOTE: If you want to check which branch is checked out in a different code directory, type:
 +
 +
git -C /path/to/Code branch
 +
 +
where <tt>/path/to/Code</tt> is the path to the other code directory.
 
|}
 
|}
 +
 +
== Deleting branches ==
 +
 +
There are several ways that you can delete Git branches:
 +
 +
=== Deleting branches with Git GUI ===
 +
 +
(1) '''Start Git GUI'''
 +
 +
git gui &
 +
 +
(2)  Select the '''Branch/Delete''' menu item.
 +
 +
[[Image:GitGuiDeleteBranch.png]]
 +
 +
(3) A dialog box will appear.  Select the name of the branch that you wish to delete.
 +
 +
(4) Click on '''Delete'''.
 +
 +
=== Deleting branches with Gitk ===
 +
 +
(1) '''Start Gitk'''.
 +
 +
gitk --all &
 +
 +
(2) Right-click on the <span style="color:green">GREEN BOX</span> that denotes the name of the branch that you wish to delete.  A context menu will appear.
 +
 +
[[Image:GitKDeleteBranch.png]]
 +
 +
(3)  Click on '''Remove this branch'''.
 +
 +
=== Deleting branches from the command line ===
 +
 +
To remove a Git branch from the command line, type:
 +
 +
git branch -d BRANCH-NAME
 +
 +
=== Deleting references to remote branches ===
 +
 +
For more information, please see [[Advanced_Git_usage#Removing_references_to_remote_branches|this section on our ''Advanced Git usage'' page]].
 +
 +
--[[User:Bmy|Bob Yantosca]] ([[User talk:Bmy|talk]]) 15:39, 24 June 2019 (UTC)
 +
 +
== Further reading ==
 +
 +
#[https://git-scm.com/book/en/v2/Git-Branching-Basic-Branching-and-Merging ''Basic branching and merging'' (Pro Git book)]
 +
#[https://it.atlassian.com/git/tutorials/using-branches ''Using branches'' (Atlassian Git tutorial)]
 +
#[https://learngitbranching.js.org/?locale=en_US ''Learn Git branching'']]
 +
#[https://datasift.github.io/gitflow/IntroducingGitFlow.html ''GitFlow (DataSift)]
 +
 +
 +
----
 +
'''''[[Using Git GUI|Previous]] | [[Committing|Next]] | [[Guide to using Git with GEOS-Chem]]'''''

Latest revision as of 20:27, 5 August 2019

Previous | Next | Guide to using Git with GEOS-Chem

  1. Introduction to Git
  2. Installing Git
  3. First-time Git setup
  4. Cloning (i.e. downloading for the first time)
  5. Ignoring files
  6. Viewing the revision history
  7. Using Git GUI
  8. Branching
  9. Committing
  10. Tagging
  11. Merging
  12. Receiving updates (aka pulling)
  13. Using patches to share your updates with others
  14. Advanced Git usage
  15. Git and Github tutorials


Overview

On this page, we describe how to create new branches with Git.

Creating branches

There are several ways that you can create new branches with Git.

Use Git Gui to create a new branch

(1) Start git GUI:

git gui &

(2) Select Branch/Create on the menu bar (or type CTRL-N).

GitGuiBranchMenu.png

(3) A dialog box will appear. Type the name of the new branch and click on Create.

NOTE: Your new branch name should adhere to the Gitflow nomenclature.

GitGuiNewBranch.png

(4) Git will automatically check out the new branch that you just created.

Use Gitk to create a new branch

You can also create a new branch very quickly from the Gitk browser.

(1) Start gitk

gitk --all &

(2) Move your mouse to the name of the commit from which you would like to create a new branch. Right-click on the name of that commit.

GitkNewBranch.png

(3) A context menu will appear. Select Create New Branch.

GitKCreateBranch.png

(4) A dialog box will appear. Type the name for your branch and click on Create.

Your new branch name should adhere to the Gitflow nomenclature.

Git will automatically check out the new branch that you just created.

Create a new branch from the command line

(1) First, check out the branch that you wish to branch off from. In this case, let's branch off master.

git checkout master

(2a) If you are creating a new feature branch, then type:

git branch feature/NAME
git checkout feature/NAME

(2b) On the other hand, if you are creating a bugfix branch, then type:

git branch bugfix/NAME
git checkout bugfix/NAME

where NAME is to be the name of the feature or bug fix that you are implementing.

--Bob Yantosca (talk) 15:25, 20 June 2019 (UTC)

Switching between (aka "checking out") branches

Check out a branch with Git GUI

(1) Start Git GUI.

git gui &

(2) Select the Branch/Checkout menu item.

GitGuiCheckOut.png

(3) A dialog box will appear. Click on the name of the branch you would like to check out.

GitGuiCheckOutBox.png

(4) Click on Checkout.

Check out a branch with GitK

(1) Start Gitk.

gitk --all &

(2) Right-click the GREEN BOX that correponds to the branch that you would like to check out.

GitKCheckOut.png

(3) A context menu will appear. Click on Check out this branch.

Check out a branch from the command line

If you are in a Git-backed code directory, and want to know what the current branch is, type:

git checkout BRANCH-NAME

If you would like to check the current branch in a different directory, use the -C option. Type:

git -C /path/to/Code checkout BRANCH-NAME

Determining which branch is checked out

You can determine which branch is currently checked-out as follows:

Using this: Follow these steps:
Git GUI Look at the top left (under the Repository menu), and you will see the name the branch that is currently checked-out.
Gitk Look for the GREEN BOX with the boldfaced name inside. This indicates the branch that is currently checked-out.
The command line Type:
git branch

and you will see all of the branches:

 dev/12.4.0
*master

The branch that is currently checked-out will have an * in front of it.

NOTE: If you want to check which branch is checked out in a different code directory, type:

git -C /path/to/Code branch

where /path/to/Code is the path to the other code directory.

Deleting branches

There are several ways that you can delete Git branches:

Deleting branches with Git GUI

(1) Start Git GUI

git gui &

(2) Select the Branch/Delete menu item.

GitGuiDeleteBranch.png

(3) A dialog box will appear. Select the name of the branch that you wish to delete.

(4) Click on Delete.

Deleting branches with Gitk

(1) Start Gitk.

gitk --all &

(2) Right-click on the GREEN BOX that denotes the name of the branch that you wish to delete. A context menu will appear.

GitKDeleteBranch.png

(3) Click on Remove this branch.

Deleting branches from the command line

To remove a Git branch from the command line, type:

git branch -d BRANCH-NAME

Deleting references to remote branches

For more information, please see this section on our Advanced Git usage page.

--Bob Yantosca (talk) 15:39, 24 June 2019 (UTC)

Further reading

  1. Basic branching and merging (Pro Git book)
  2. Using branches (Atlassian Git tutorial)
  3. Learn Git branching]
  4. GitFlow (DataSift)



Previous | Next | Guide to using Git with GEOS-Chem