coder101
coder101

Reputation: 455

Unable to execute command with forward slash

I want to create a batch file to execute a set of Git commands to:

  1. Fetch a new remote repository.
  2. Create a local repository to track the remote and check the new local branch out.

Second Git command uses a forward slash (origin/[repositoryName]) and gives the following error:

"fatal: Missing branch name; try -b".

@ECHO OFF
SET /P branch = Enter remote branch name:
git fetch origin %branch%
git checkout --track origin/%branch%

First, git command fetches the remote repository.

Second git command gives error:

"fatal: "Missing branch name; try -b"

Upvotes: 0

Views: 177

Answers (1)

double-beep
double-beep

Reputation: 5518

As mentioned in comments you should use the following piece of code:

@echo off
set /p "branch=Enter remote branch name: "
git fetch origin %branch%
git checkout --track origin/%branch%

which is slightly modified.

  • You don't need to scream in batch file :) it is a case insensitive language.
  • When you set variables don't add extra spaces around the =. Because then, interpreter interprets it as var<space> and <space>value.
  • Also, quote variable name and value in format like: set "var=value".

Upvotes: 2

Related Questions