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
No edit summary
No edit summary
Line 30: Line 30:
===How To===
===How To===
* '''2019-10-07''' [https://linuxize.com/post/how-to-rename-local-and-remote-git-branch/ How To Rename a Local and Remote Git Branch]
* '''2019-10-07''' [https://linuxize.com/post/how-to-rename-local-and-remote-git-branch/ How To Rename a Local and Remote Git Branch]
** Basically: <tt>git branch -m {{arg|new_name}}</tt> renames the branch locally and doesn't mess with anything upstream. It's like you just created {{arg|new_name}} and put stuff in it.
** Basically: {{fmt/code|git branch -m {{arg|new_name}}}} renames the branch locally and doesn't mess with anything upstream. It's like you just created {{arg|new_name}} and put stuff in it.
** Note: if the branch is not in the local repository, then you just need to [[git fetch]] it after the <code>git checkout &lt;old_name&gt;</code>.
** Note: if the branch is not in the local repository, then you just need to [[git fetch]] it after the <code>git checkout &lt;old_name&gt;</code>.
** Also: <tt>git branch -c {{arg|new_name}}</tt> to copy instead of renaming.
** Also: {{fmt/code|git branch -c {{arg|new_name}}}} to copy instead of renaming.

Revision as of 20:42, 11 June 2023

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:

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
  • Template:L/sub 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

How To