Search code examples
gitshellteamcityagentgit-log

How do I get 'git log' in the terminal or using a shell script when not in a repository


I have Teamcity build agent, where I need to extract the git log from a repository. The trouble is, when my shell script runs, it's not in git repository, so git log doesn't work out of the box.

Does anyone know how to achieve this.

I have search the documentation, but I can't seem to find any way of doing it.

Problem solving so far

  1. When Teamcity "clones" a project from Github on to the agent, it doesn't actually clone the whole thing. So the working directory is not a repository.

  2. I do not have SSH access to github when running my shell script, which I need

Thanks in advance.

Solution

See accepted answer below.


Solution

  • Use the -C flag of the git command. It allows you to specify the git directory.

    git -C 'git-working-dir' log