To fetch a branch from a remote Git repository and start working on it locally, open Terminal in your repository, fetch from the correct remote, then create a local branch that tracks the remote branch. For example, git fetch origin followed by git switch --track origin/feature/login creates and switches to a local feature/login branch linked to origin/feature/login.
Open Terminal in the repository
Open Terminal and move to the folder containing your Git repository. In macOS Terminal, the default shell is zsh, though your setup may use a different shell. Git commands below work in either; branch names that contain shell metacharacters should be quoted so the shell does not interpret them. Apple’s Terminal guide
If you already have the repository open in a code editor, use its integrated terminal if available. Otherwise, in Terminal, type cd , drag the repository folder from Finder into the Terminal window to insert its path, then press Return. Check that you are in the right repository and review any local changes before switching branches:
git status --short
git remote -v
git remote -v lists configured remote names and URLs. The commands below use origin, a common remote name; replace it with the actual name shown on your Mac. If no remote is listed, this repository does not currently have a configured remote to fetch from.
Fetch the remote branch
Run:
git fetch origin
Fetching downloads commits and references from the remote and updates local remote-tracking references according to the repository’s fetch configuration. It does not by itself switch your working directory to the branch. In the usual configuration, fetched branches from origin appear as names such as origin/feature/login. Git documents fetch as updating remote-tracking branches, with the exact mapping controlled by the remote’s fetch refspec. Git fetch documentation
You can confirm the branch is visible locally with:
git branch --remotes
Look for origin/feature/login in the output. If it is absent, check that the branch name and remote are correct, that you can access the remote, and that the remote’s fetch configuration includes that branch. A successful fetch may still not show every server branch if the repository uses a restricted refspec.
Create and switch to the local tracking branch
When the remote-tracking branch is present and you want the local branch to use the same name, run:
git switch --track origin/feature/login
Git creates a local feature/login branch, sets its upstream to origin/feature/login, and switches your working tree to it. The tracking relationship lets commands such as git status report how the local branch compares with its upstream, and gives Git a default upstream for operations such as git pull. The --track option sets that upstream; Git derives the local name from the remote-tracking branch in this form. Git switch documentation
If you want a different local branch name, specify it explicitly:
git switch --track --create login-work origin/feature/login
This creates local login-work tracking origin/feature/login. In Git versions that support the newer switch command, --create is the long form of -c. Check your installed version with git --version if Git reports that switch is unknown; git switch was introduced in Git 2.23. In that case, use the older equivalent:
git checkout --track -b login-work origin/feature/login
Verify the branch and handle common errors
After switching, confirm the active branch and tracking status:
git status -sb
git branch -vv
The status output should identify the local branch and its upstream. In the branch listing, login-work should show origin/feature/login as its tracking branch.
If Git says the branch is ambiguous, use the fully specified remote/branch form shown above rather than relying on automatic guessing. Git’s shorthand git switch feature/login can automatically create a tracking branch when exactly one remote has a matching branch, but ambiguity can arise when multiple remotes have that name. Git switch documentation
If switching is refused because local changes would be overwritten, stop and review git status before proceeding. Commit or safely stash work you want to keep; do not force the switch or discard changes unless you understand what will be lost. If the local branch name already exists, choose that branch deliberately or select a different local name with --create; do not assume an existing branch already tracks the remote you intended.
The workflow is complete when the intended local branch is checked out and its upstream points to the intended remote branch. Fetching refreshes what your local repository knows about the remote; creating the tracking branch gives you a local place to work while preserving that connection.
Sources
Change the default shell in Terminal on Mac — Apple Support