Git/branch: Difference between revisions

from HTYP, the free directory anyone can edit if they can prove to me that they're not a spambot
Brief usage sketch
git checkout -b
Line 12: Line 12:
* <code>git branch {{arg|name}}</code> creates a new branch called "name", pointing at the current {{l/same|HEAD}} revision
* <code>git branch {{arg|name}}</code> creates a new branch called "name", pointing at the current {{l/same|HEAD}} revision
* <code>git {{l/same|checkout}} {{arg|name}}</code>  moves {{l/same|HEAD}} to point to the branch called "name"
* <code>git {{l/same|checkout}} {{arg|name}}</code>  moves {{l/same|HEAD}} to point to the branch called "name"
** Note: <code>git {{l/same|checkout}} -b {{arg|name}}</code> accomplishes both of the above in a single command


The basic sequence of events for creating a new branch called "test", updating it, then reverting back to the original branch:
The basic sequence of events for creating a new branch called "test", updating it, then reverting back to the original branch:

Revision as of 16:27, 27 May 2018

A "branch" is a separate copy (of the files involved in a project) which can be worked on without affecting the original copy.

"Branching" is a concept basic to most version control systems.

Commands

Information:

  • git branch lists local branches
  • git branch -r lists the remote branches
  • git branch -a lists both local and remote branches

Actions:

  • git branch <name> creates a new branch called "name", pointing at the current [[../HEAD|HEAD]] revision
  • git [[../checkout|checkout]] <name> moves [[../HEAD|HEAD]] to point to the branch called "name"
    • Note: git [[../checkout|checkout]] -b <name> accomplishes both of the above in a single command

The basic sequence of events for creating a new branch called "test", updating it, then reverting back to the original branch:

  • git branch test - create the branch
  • git checkout test - switch to it
  • stage whatever changes you want to include in "test"
    • This can include adding any new files you've created for this branch.
  • git commit -a -m 'made a change' - commit the change to "test"
  • git checkout master - switch back to the main branch (removes new files, restores any you deleted)

Reference