diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index b4b8016..967a658 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -9,7 +9,6 @@ pages: before_script: - export PATH="$PATH:$CARGO_HOME/bin" - mdbook --version || cargo install --debug mdbook - - cargo install mdbook-toc script: - mdbook build -d public only: diff --git a/src/SUMMARY.md b/src/SUMMARY.md index f456093..6b350bd 100644 --- a/src/SUMMARY.md +++ b/src/SUMMARY.md @@ -15,8 +15,10 @@ * [Fixing commits](commits/fixing.md) * [Stashing](stashing.md) * [Collaboration](collaboration.md) -* [Branches](branching.md) - * [Rebasing](rebasing.md) +* [Branching](branching.md) + * [Rebasing](branching/rebasing.md) + * [Reporting](branching/reporting.md) + * [Worktree](branching/worktree.md) * [Tags](tags.md) * [Logging](logging.md) * [Output examples](logging/outputs.md) diff --git a/src/branching.md b/src/branching.md index fb16e66..f5d6133 100644 --- a/src/branching.md +++ b/src/branching.md @@ -1,6 +1,6 @@ # Branching ```bash -# Create a new branch. +# Create a new branch. Stay in the current branch. git branch # Create a new branch at a specific commit, and switch to it. @@ -42,12 +42,6 @@ git merge master # Abort a merge (such as if there's conflicts that need to be resolved differently). git merge --abort -# Delete a branch. -git branch -d my_new_branch - -# Delete a branch on the remote. -git push origin :my_new_branch - # Merge two local branches, without fast-forwarding, with default editor opening to modify the message. git merge --no-ff --edit @@ -74,6 +68,15 @@ git cherry-pick -n # Rename the current branch git branch -m +# Show all local branches with last commit message. +git branch -v + +# Above, plus corresponding remote branch name. Also includes worktree path, if applicable. +git branch -vv +``` + +## Navigating +```bash # Get the name of the previous branch. git rev-parse --symbolic-full-name @{-1} # For PowerShell. @@ -82,32 +85,12 @@ git rev-parse --symbolic-full-name '@{-1}' ## Management ```bash -# Show all current branches, including remotes. -git show-branch -a --list +# Delete a branch. +git branch -d my_new_branch -# Show all local branches that have been merged into master. -git branch --merged - -# Show all local branches that have not been merged into master. -git branch --no-merged - -# Show all local branches, sorted by and showing last commit -# https://stackoverflow.com/a/5188364/11912 -git for-each-ref --sort=committerdate refs/heads/ --format='%(HEAD) %(color:yellow)%(refname:short)%(color:reset) - %(color:red)%(objectname:short)%(color:reset) - %(contents:subject) - %(authorname) (%(color:green)%(committerdate:relative)%(color:reset))' +# Delete a branch on the remote. +git push origin :my_new_branch # Do a dry run of pruning local branches that no longer exist on a remote. git remote prune origin --dry-run ``` - -## Worktree - -```bash -# List all worktrees for the current repo. -git worktree list - -# Create a new worktree for a specific branch. Path can't be a current working directory. -git worktree add ../path/for/branchName - -# Delete a worktree. -git worktree remove path/to/worktree -``` diff --git a/src/rebasing.md b/src/branching/rebasing.md similarity index 100% rename from src/rebasing.md rename to src/branching/rebasing.md diff --git a/src/branching/reporting.md b/src/branching/reporting.md new file mode 100644 index 0000000..cd0718c --- /dev/null +++ b/src/branching/reporting.md @@ -0,0 +1,15 @@ +# Reporting +```bash +# Show all current branches, including remotes. +git show-branch -a --list + +# Show all local branches that have been merged into master. +git branch --merged + +# Show all local branches that have not been merged into master. +git branch --no-merged + +# Show all local branches, sorted by and showing last commit +# https://stackoverflow.com/a/5188364/11912 +git for-each-ref --sort=committerdate refs/heads/ --format='%(HEAD) %(color:yellow)%(refname:short)%(color:reset) - %(color:red)%(objectname:short)%(color:reset) - %(contents:subject) - %(authorname) (%(color:green)%(committerdate:relative)%(color:reset))' +``` diff --git a/src/branching/worktree.md b/src/branching/worktree.md new file mode 100644 index 0000000..fdedccf --- /dev/null +++ b/src/branching/worktree.md @@ -0,0 +1,12 @@ +# Worktree + +```bash +# List all worktrees for the current repo. +git worktree list + +# Create a new worktree for a specific branch. Path can't be a current working directory. +git worktree add ../path/for/branchName + +# Delete a worktree. +git worktree remove path/to/worktree +```