gitsw -c feature-newgitsw --create bugfix/auth-error```textThe new branch is created from your current HEAD position.### Implementation DetailsFrom `src/main.rs:432-448`:```rust// Step 2: Create branch if needed, then switchif !branch_exists && create { println!( "{} Creating branch '{}'...", "info:".blue().bold(), target_branch.green() ); repo.create_branch(target_branch)?;}println!( "{} Switching to '{}'...", "info:".blue().bold(), target_branch.green());repo.switch_branch(target_branch)?;
Branch creation happens after stashing changes from your current branch, ensuring a clean switch.
If the branch has an associated stash, gitsw warns you and drops it:
$ gitsw -d feature-branchwarning: Branch has a stash. It will be dropped.? Delete branch 'feature-branch'? (y/N) ydone: Deleted branch 'feature-branch'
From src/main.rs:268-300:
// Check for stash and offer to clean upif let Some(branch_state) = state.get_branch(branch_name) { if let Some(stash_id) = &branch_state.stash_id { if let Ok(stash_oid) = Oid::from_str(stash_id) { println!( "{} Branch has a stash. It will be dropped.", "warning:".yellow().bold() ); if prompt::confirm_delete(branch_name)? { let _ = repo.stash_drop(stash_oid); } else { println!("{} Delete aborted.", "info:".blue().bold()); return Ok(()); } } }}// Delete the branchrepo.delete_branch(branch_name)?;state.remove_branch(branch_name);state.save()?;```bash## Listing BranchesWhile gitsw doesn't have a dedicated list command, you can view branches in several ways:### Interactive PickerRun `gitsw` without arguments to see all branches:```bashgitsw
gitsw -lgitsw --list```textOutput:```bashBranches with stashed changes: feature-auth (stash present, last visited 2 hours ago)* develop (stash present, last visited 5 min ago) bugfix/login (stash present, last visited yesterday)
From src/main.rs:154-204:
fn list_stashes() -> Result<()> { let mut repo = GitRepo::open()?; let state = StateManager::load(repo.git_dir())?; let current_branch = repo.get_current_branch()?; let stashes = repo.list_stashes()?; let branches_with_stashes = state.branches_with_stashes(); if branches_with_stashes.is_empty() { println!("{}", "No branches with git-switch stashes found.".dimmed()); return Ok(()); } println!("{}", "Branches with stashed changes:".bold()); for (branch_name, branch_state) in branches_with_stashes { let is_current = branch_name == current_branch; let marker = if is_current { "* " } else { " " }; let stash_exists = branch_state.stash_id.as_ref().is_some_and(|id| { Oid::from_str(id) .map(|oid| stashes.iter().any(|s| s.oid == oid)) .unwrap_or(false) }); let stash_status = if stash_exists { "stash present".yellow() } else { "stash missing".red() }; println!( "{}{} ({}, last visited {})", marker, branch_name, stash_status, time_display ); }}```bash### Recent BranchesView your recently visited branches:```bashgitsw -rgitsw --recent
Output:
Recent branches:* [1] develop [stash] (5 min ago) [2] main (2 hours ago) [3] feature-auth [stash] (yesterday) [4] bugfix/login (3 days ago)```bash<Note> The `[stash]` indicator shows branches with uncommitted changes that were stashed by gitsw.</Note>## Branch StatusCheck the status of your current branch:```bashgitsw -sgitsw --status
Output:
Branch: feature-authChanges: 2 modified, 1 untrackedStash: presentPackage manager: npmTracking: origin/feature-auth```textFrom `src/main.rs:110-152`:```rustfn show_status() -> Result<()> { let mut repo = GitRepo::open()?; let state = StateManager::load(repo.git_dir())?; let current_branch = repo.get_current_branch()?; println!("{} {}", "Branch:".bold(), current_branch.green()); // Check for uncommitted changes if repo.has_uncommitted_changes()? { let summary = repo.get_changes_summary()?; println!("{} {}", "Changes:".bold(), summary.yellow()); } else { println!("{} {}", "Changes:".bold(), "clean".dimmed()); } // Check for stash if let Some(branch_state) = state.get_branch(¤t_branch) { if branch_state.stash_id.is_some() { println!("{} {}", "Stash:".bold(), "present".yellow()); } } // Check remote tracking if let Some(remote) = repo.get_tracking_remote(¤t_branch)? { println!("{} {}", "Tracking:".bold(), remote); }}