elijah
elijah

Reputation: 2924

Is there a way to run a command on a different git branch?

I have a large rails project with several feature branches active at any one time. We have a long running task (rebuild the db, run the tests).

I would like to be able to run the test task on one feature branch while changing code on another. Is there a way to run a particular command on a certain branch, but have another branch active in another terminal?

Upvotes: 0

Views: 1029

Answers (2)

user456814
user456814

Reputation:

Some Git commands can operate on any reference, it doesn't have to be the branch currently checked out into your working copy:

git log <branch>
git diff <branch-one> <branch-two>

Other Git commands only operate on the branch you currently have checked out in your working copy:

git reset --hard head@{1}

If your tests depend on there being a certain branch checked out into your working copy, then as far as I know, you can't have more than one branch checked out into your working copy, you can only have 1 working copy.

As an alternative, you could possibly just clone your local repo again to get a second working copy that way:

git clone <path to local repo> second-repo

Upvotes: 3

Shade
Shade

Reputation: 785

I dont think so...

If this behavior is really needed, and going to be used often, it might be worth it to clone your repository again in a different location.

Are you trying to run a command that will take a long time to run?

You could merge the two branches and run the command from the first branch, while still working on the stuff from the other branch, if your project allows.

Upvotes: 1

Related Questions