I am trying to access a branch's commit history on a remote repository. I had a look at the doc but could not find any substantial information on how to access a remote repo's commit history using my local git client.
-
1`lg2 = log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold cyan)%aD%C(reset) %C(bold green)(%ar)%C(reset)%C(bold yellow)%d%C(reset)%n'' %C(white)%s%C(reset) %C(dim white)- %an%C(reset)' --all` I don't know where I get this, but It works for me – Liu Hao Nov 02 '22 at 02:42
11 Answers
git log remotename/branchname
Will display the log of a given remote branch in that repository, but only the logs that you have "fetched" from their repository to your personal "copy" of the remote repository.
Remember that your clone of the repository will update its state of any remote branches only by doing git fetch
. You can't connect directly to the server to check the log there, what you do is download the state of the server with git fetch
and then locally see the log of the remote branches.
Perhaps another useful command could be:
git log HEAD..remote/branch
which will show you the commits that are in the remote branch, but not in your current branch (HEAD
).

- 62,887
- 36
- 269
- 388

- 10,385
- 4
- 44
- 57
-
12"You can't connect directly to the server to check the log there" - that was the issue I was having – Brian J Jul 02 '14 at 13:48
-
1I'm only getting local pulled changes... note the remote ones, even doing fetch before. – Loenix Jul 08 '15 at 07:41
-
7
-
34That's too bad, so I have to clone 2GB worth of objects just to look through the commit logs? – TWiStErRob Apr 11 '16 at 11:38
-
I just verified this by running the command on a repo I knew I was locally behind on; the first entry returned reflected the latest commit remotely – ds011591 Sep 08 '16 at 12:37
-
2Hi @TWiStErRob you can mitigate pain by managing the amount of data fetched with a shallow clone (see --depth in https://git-scm.com/docs/git-clone), then manage fetches with (see "shallow" in https://git-scm.com/docs/git-fetch). – qneill May 12 '17 at 14:04
-
This answer was helpful, and then https://stackoverflow.com/a/31625264/470749 and https://stackoverflow.com/a/34414393/470749 added more helpful information too. – Ryan Apr 12 '20 at 12:32
NB. "origin" below use to represent the upstream of a cloned repository, replace "origin" with a descriptive name for the remote repo. "remote reference" can use the same format used in clone command.
git remote add origin <remote reference>
git fetch
git log origin/master

- 2,814
- 2
- 18
- 23

- 1,240
- 8
- 6
-
-
2@user1795998 The remote repository Git URL, e.g. `git://git.somedomain.tld/some/repo` – gertvdijk Dec 18 '12 at 22:01
-
2Don't you need to specify `
` when fetching (or use `fetch --all`) if you're not tracking any branch on the remote? – gertvdijk Dec 18 '12 at 22:04 -
@all - lets ay I want to fetch from git URL:https://git.qrepo.com from branch "master" and project "vendor/diag" ,what would be the commands? – user1795998 Dec 18 '12 at 22:06
-
1What do you mean with "project vendor/diag"? Is that a folder inside the repository? Another branch? – Maic López Sáenz Dec 19 '12 at 01:13
-
@LopSae - a repository has multiple projects and branches..vendor/diag is another project,I still cant get these commands to work – user1795998 Dec 19 '12 at 04:02
-
1A repository can have multiple branches, but "project" is not a term related to git, from there the confusion to what a "project" means in this case. Still, what would that have to do with the question? – Maic López Sáenz Dec 19 '12 at 05:59
-
2I don't believe its possible to do this in GIT. You must clone that remote repository before you can issue a git log against it. – user959690 Jan 26 '15 at 19:23
I'm not sure when filtering was added but it's a way to exclude the object blobs if you only want to fetch the history/ref-logs:
git clone --filter=blob:none --no-checkout --single-branch --branch master git://some.repo.git .
git log

- 9,278
- 1
- 33
- 38
-
7This is *perfect*. Given the other answers, it would be awesome if this were able to stand out next to the provided answer. – Eric Cousineau Jun 04 '20 at 00:24
-
2
-
4Also, since you are checking out a specific branch you can also add --filter=tree:0 to exclude other branch trees. Adding tree:0 was 75% smaller than without. – Scott Carlson Mar 26 '22 at 15:39
A fast way of doing this is to clone using the --bare
keyword and then check the log:
git clone --bare git@giturl tmpdir
cd tmpdir
git log branch

- 1,029
- 1
- 11
- 18
This is what worked for me:
git fetch --all
git log production/master
Note that this fetches from ALL remotes, i.e. potentially you "have to clone 2GB worth of objects just to look through the commit logs".

- 32,129
- 35
- 168
- 232
You can only view the log on a local repository, however that can include the fetched branches of all remotes you have set-up.
So, if you clone a repo...
git clone git@gitserver:folder/repo.git
This will default to origin/master
.
You can add a remote to this repo, other than origin
let's add production
. From within the local clone folder:
git remote add production git@production-server:folder/repo.git
If we ever want to see the log of production
we will need to do:
git fetch --all
This fetches from ALL remotes (default fetch without --all
would fetch just from origin
)
After fetching we can look at the log on the production
remote, you'll have to specify the branch too.
git log production/master
All options will work as they do with log on local branches.

- 29,401
- 18
- 105
- 117
I don't believe this is possible. I believe you have to clone that remote repo locally and perform git fetch
on it before you can issue a git log
against it.

- 3,956
- 8
- 38
- 58

- 602
- 9
- 16
-
1imagine you already clone the repo to local and make some changes . . then you want to check if anyone has committed to the remote repo – Chhorn Elit Dec 20 '15 at 08:50
-
3If you change this answer to "It is not possible" then this is the best answer. There is no way to access a remote repo's commit history using a remote git client. – qneill May 12 '17 at 14:00
git
isn't a centralized scm like svn
so you have two options:
- Use the web interface of target platforms (f.e. GitHub REST API or GitLab REST API)
- Download the repository and display logs locally
It may be annoying to implement for many different platforms (GitHub, GitLab, BitBucket, SourceForge, Launchpad, Gogs, ...) but fetching data is pretty slow (we talk about seconds) - no solution is perfect.
An example with fetching into a temporary directory:
git clone https://github.com/rust-lang/rust.git -b master --depth 3 --bare --filter=blob:none -q .
git log -n 3 --no-decorate --format=oneline
Alternatively:
git init --bare -q
git remote add -t master origin https://github.com/rust-lang/rust.git
git fetch --depth 3 --filter=blob:none -q
git log -n 3 --no-decorate --format=oneline origin/master
Both are optimized for performance by restricting to exactly 3 commits of one branch into a minimal local copy without file contents and preventing console outputs. Though opening a connection and calculating deltas during fetch takes some time.
An example with GitHub:
GET https://api.github.com/repos/rust-lang/rust/commits?sha=master&per_page=3
An example with GitLab:
GET https://gitlab.com/api/v4/projects/inkscape%2Finkscape/repository/commits?ref_name=master&per_page=3
Both are really fast but have different interfaces (like every platform).
Disclaimer: Rust and Inkscape were chosen because of their size and safety to stay, no advertisement

- 2,646
- 21
- 33
Here's a bash function that makes it easy to view the logs on a remote. It takes two optional arguments. The first one is the branch, it defaults to master. The second one is the remote, it defaults to staging.
git_log_remote() {
branch=${1:-master}
remote=${2:-staging}
git fetch $remote
git checkout $remote/$branch
git log
git checkout -
}
examples:
$ git_log_remote
$ git_log_remote development origin

- 6,931
- 1
- 10
- 17
-
1Why are you doing `git checkout $remote/branch ; git log ; git checkout -`. Wouldn't just `git log $remote/branch` work here? – Michael Firth Jan 28 '21 at 11:50
-
@MichaelFirth I just checked and indeed it would. Knowing that really make the helper function obsolete. Thanks! – Brandon Howard Feb 01 '21 at 18:26
I was looking for remote branches that contained a particular commit
here's a quick script you can use as an example
spark
✦ ❯ cat run.sh
for b in $(git branch -r)
do
hasKryoCommit=$(git log "$b" | grep 3e033035a3c0b7d46c2ae18d0d322d4af3808711)
if test -n "$hasKryoCommit"
then
echo "$b"
fi
done
spark
✦ ❯ bash run.sh
origin/HEAD
fatal: unrecognized argument: ->
origin/master
origin/branch-2.4
origin/branch-3.0
origin/branch-3.1
origin/branch-3.2
origin/master

- 746
- 1
- 9
- 21
You can easily get the log of the remote server. Here's how:
(1) If using git via ssh - then just login to the remote server using your git login and password-- and chdir the remote folder where your repository exists- and run the "git log" command inside your repository on the remote server.
(2) If using git via Unix's standard login protocol- then just telnet to your remote server and do a git log there.
Hope this helps.

- 174
- 1
- 2
-
14To rephrase, "you can't get a log of a remote server, you have to login and get the log using a local git client" – qneill May 12 '17 at 14:06
-
Just delete this answer, it does not answer the question and its not how most git users do not have server shell access – nhed Jun 04 '20 at 21:28
-
#2: I've been using and hacking various UNIX and Linux distros for almost 30 years and that doesn't make much sense to me... – Thomas Guyot-Sionnest Jul 23 '21 at 21:17