Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Will remote URL for fetch and push be different?

Tags:

git

git-remote

git remote --v show remote info

origin  https://github.com/test/testing-iOS.git (fetch) origin  https://github.com/test/testing-iOS.git (push) 

It shows that both fetch and push are using the same remote URL.

Question:

When will (if ever) remote URL for fetch and push be different?

What commands can you use to change remote URL for fetch or push separately?

like image 469
Boon Avatar asked Jul 31 '15 13:07

Boon


People also ask

Does git fetch connect to a remote?

Fetching and pulling from Git remotes Once a remote record has been configured through the use of the git remote command, the remote name can be passed as an argument to other Git commands to communicate with the remote repo. Both git fetch , and git pull can be used to read from a remote repository.

What is a remote repository URL?

A remote URL is Git's fancy way of saying "the place where your code is stored." That URL could be your repository on GitHub, or another user's fork, or even on a completely different server. You can only push to two types of URL addresses: An HTTPS URL like https://github.com/user/repo.git.

How do I find my remote URL?

You can view that origin with the command git remote -v, which will list the URL of the remote repo.


1 Answers

Yes (using different remote), and that is why Git 2.5 introduces a new ref shorthand @{push}.
See "Viewing Unpushed Git Commits"

What commands can you use to change remote URL for fetch or push separately?

You need a separate remote:

git remote add myfork /url/for/my/fork git config remote.pushdefault myfork 

The GitHub blog post "Improved support for triangular workflows" illustrates the use of @{push}:

https://cloud.githubusercontent.com/assets/1319791/8943755/5dcdcae4-354a-11e5-9f82-915914fad4f7.png

See what commits you've added to your current branch since the last push:

git clone https://github.com/YOUR-USERNAME/atom cd atom git config remote.pushdefault origin git config push.default current 
  • remote.pushdefault specifies where to push (to which remote repo).
  • push.default specifies what to push (what refspec), when no refspec is explicitly given.
    current, in that latter case, means "push the current branch to update a branch with the same name on the receiving end."

The following branch will fetch from one url, push to another:

git remote add upstream https://github.com/atom/atom git fetch upstream git checkout -b whizbang upstream/master 

(Here the whizbang branches tracks upstream/master, but pushes to origin/whizbang)

git log @{push}.. 

This uses the new @{push} notation, which denotes the current value of the remote-tracking branch that the current branch would be pushed to by git push, namely origin/whizbang.
You can also refer to the push destination of an arbitrary branch using the notation whizbang@{push}.

like image 147
VonC Avatar answered Oct 02 '22 08:10

VonC