I'm trying to set up a service that will update my repository automatically when it detects changes on the remote branch. Before anyone mentions it, I'm aware that embedding the password in the URL is bad practice. I'm currently using:
git fetch https://<user>:<pass>@github.com/<org>/<repo>
Which gives an output of:
From https://github.com/<org>/<repo>
* branch development -> FETCH_HEAD
When I run git status
after doing the fetch, it doesn't detect the most recent changes.
If I run a normal git fetch
without the URL and supply the username and password manually, I get a different output:
From https://github.com/<org>/<repo>
96353f7..e88782c development -> origin/development
And then running git status
works as predicted and detects that there are changes on the remote branch.
I'm not very experienced with Git and I feel like I'm missing something very obvious. Where is my error?
Edit
So it looks like the missing piece was for me to specify the local and remote branch after the URL:
git fetch https://<user>:<pass>@github.com/<org>/<repo> development:origin/development
As the accepted answer points out: if you don't specify the remote name, git puts the remote changes in the default FETCH_HEAD. This is resolved by specifying the local and remote branches explicitly.
I'm still a little confused as to why git fetch
knows to grab from the origin remote by default, but specifying the URL changes this default. But it's working now in any case