Actions26
Overview
The "Switch Branch" operation in this Git Extended node allows users to switch the current working branch or commit in a local Git repository. It supports optionally creating a new branch if it does not already exist. This operation is useful when automating workflows that require changing the active branch, such as preparing for development on a feature branch, switching to a release branch, or checking out a specific commit for testing.
Practical examples:
- Switching to an existing branch named
feature/loginbefore running build or test scripts. - Creating and switching to a new branch
hotfix/urgent-fixif it doesn't exist yet. - Automating deployment pipelines where the codebase must be switched to a specific commit or branch before packaging.
Properties
| Name | Meaning |
|---|---|
| Repository Path | Filesystem path to run the Git command from. For clone operations, the repository will be created inside this path. |
| Target | Branch or commit to operate on (the branch or commit to switch to). |
| Create | Whether to create the branch if it does not exist (boolean). |
| Skip Stdout | Whether to ignore command output to avoid maxBuffer errors (boolean). |
Output
The node outputs JSON data containing the standard output (stdout) and standard error (stderr) of the executed Git command unless the "Skip Stdout" property is enabled. In that case, the output JSON will be empty.
Output structure example when not skipping stdout:
{
"stdout": "<trimmed command output>",
"stderr": "<trimmed error output>"
}
If "Skip Stdout" is true, the output JSON will be:
{}
No binary data output is produced by this operation.
Dependencies
- Requires Git installed and accessible via the command line on the machine where n8n runs.
- The node executes Git commands using the system shell.
- No external API keys or services are required specifically for the "Switch Branch" operation.
- The node requires appropriate filesystem permissions to access the specified repository path.
Troubleshooting
Common issues:
- Invalid repository path: Ensure the
Repository Pathpoints to a valid Git repository. - Non-existent target branch or commit: If
Createis false and the target branch does not exist, the Git command will fail. - Permission errors: Make sure the n8n process has read/write access to the repository directory.
- Buffer overflow errors: Large command output may cause buffer issues; enable
Skip Stdoutto avoid this.
- Invalid repository path: Ensure the
Error messages:
"Unsupported operation switch": Indicates the operation name was not recognized; ensure the operation is set correctly.- Git errors like
"error: pathspec '<target>' did not match any file(s) known to git": Means the target branch or commit does not exist andCreatewas not enabled. "Command failed with exit code <code>": General failure of the Git command; check the command syntax and repository state.