pmiranda
pmiranda

Reputation: 8450

git, use commands on branch that is being used

Lets say that I have this:

C:\project (release/FASE_F2_E4_V3)
λ git pull origin release/FASE_F2_E4_V3

Is there a way to pull, push or execute a git comand without specifying the actual branch?

I mean, something like:

git pull origin (actual_branch)

and not

git pull origin a_very_long_name_of_the_branch

Edit:

this is what I get with git pull and git the branch explicit:

enter image description here

Upvotes: 0

Views: 50

Answers (2)

RJFalconer
RJFalconer

Reputation: 11701

For push you want:

git config --global push.default current

If you are on your local release/FASE_F2_E4_V3 branch running git push will push to the origin branch of the same name.

pull should already behave like this; pulling when on release/FASE_F2_E4_V3 will pull from origin release/FASE_F2_E4_V3, assuming you created your local branch from that.

If you want your local release/FASE_F2_E4_V3 to map to a longer-named branch on the remote then you do indeed have to follow the set-upstream-to command as per your question.

Upvotes: 1

Shridhar R Kulkarni
Shridhar R Kulkarni

Reputation: 7063

If you run git pull, the branch that is currently checked out will be pulled.

If you want to pull a branch without specifying name in git pull, you will have to checkout that particular branch.

For example, you have currently checked out branch A and you want to pull branch B then first checkout branch B and the run git pull.

git checkout B
git pull

After you edit the question:

In the image you have posted, it says to run git pull you should have an upstream branch i.e set the default remote branch for the current local branch so that git pull understands which branch to pull from.

As shown in the image, run the below command to set an upstream:

git branch --set-upstream-to=origin/<branch> release/FASE_F2_E4_V3

To learn more about --set-upstream, you might want to read this.

Upvotes: 0

Related Questions