V
V
Vlad Osadchyi2019-07-22 10:53:30
cmd/bat
Vlad Osadchyi, 2019-07-22 10:53:30

How to find out the name of the current git branch in batch and switch to this branch in another folder?

There are several folders with the same php project (such as subdomains). To speed up the process of syncing these folders, I made this .bat file that I run after git push in the main folder

@echo off
cd D:\OSPanel\domains\app-main
git pull
cd D:\OSPanel\domains\5m.app.local
git pull
cd D:\OSPanel\domains\app


It is launched from the D:\OSPanel\domains\app folder. But since I can work on different branches in the main folder, I need to git checkout to the current branch from D:\OSPanel\domains\app in subdomains. Tell me how to find out the name of the current branch and go to it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Saboteur, 2019-07-22
@VladOsadchyi

Transfer the baht to the shell - if you have git, then git-bash is worth it. On the shell, this is easily solved

cd DIR_MAIN
BRANCH=$(git rev-parse --abbrev-ref HEAD)

cd DIR_1
git checkout $BRANCH
git pull

cd DIR_2
git checkout $BRANCH
git pull

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question