- Branching means you diverge from the main line of development and continue to do work without changing the main line
- independent line of development
- think of them as a way to request a brand new working directory, staging area, and project history
- in Git, branches are a part of your everyday development process.
- when you want to add a new feature or fix a bug—no matter how big or how small, spawn a new branch to encapsulate your changes
- this makes sure that unstable code is never committed to the main code base
- it gives you the chance to clean up your feature’s history before merging it into the main branch
git branch
git branch practice
git branch
git checkout practice
Note: 'wip' = 'work in progress'
-
List branches
$ git branch
-
Create a new branch
$ git branch practice
-
Navigate between branches
$ git checkout branchname
-
Create and switch to branch (2 steps in 1 line)
$ git checkout -b testbranch
-
Delete a branch (safe delete; won't delete if there are unmerged changes)
$ git branch -d practice
-
Delete a branch (force delete; will delete even if branch has unmerged changes)
$ git branch -D practice
-
Rename a branch (whichever is the current one, be careful)
$ git branch -m newone_wip
-
Rename a branch (can specify oldname and newname)
$ git branch -m <oldname> <newname>
-
Back to main branch
$ git checkout master
-
Merge branches (will merge specified into current branch)
$ git merge <branchname>
git push <remote_name> <branch_name>
Example:
git push origin practice
Run this from the branch where you want the file to end up:
on: master
branch
git checkout branch_wip myfile.txt
on: master
branch
git checkout branch_wip myfolder/**
~/git_work/data-science-from-scratch practice ✔ 498d
▶ jupyter notebook