# Chain several shell commands to get current commit of git folder

**URL:** <https://discourse.julialang.org/t/chain-several-shell-commands-to-get-current-commit-of-git-folder/14359>\
**Category:** General Usage\
**Tags:** shell, git\
**Created:** [August 31, 2018, 11:58am UTC](https://discourse.julialang.org/t/chain-several-shell-commands-to-get-current-commit-of-git-folder/14359 "2018-08-31T11:58:27Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![migarstka](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/migarstka/32/3828_2.png) [@migarstka](https://discourse.julialang.org/u/migarstka)\
**Post date:** [August 31, 2018, 11:58am UTC](https://discourse.julialang.org/t/chain-several-shell-commands-to-get-current-commit-of-git-folder/14359/1 "2018-08-31T11:58:27Z")

</div>

Let’s say I want to print the information of the latest commit hash of a git repo to a result file.

The following command would give a string of the latest commit for the current folder.

```julia
commit = read(`git rev-parse HEAD`,String)[1:7]

```

However, I want the latest commit of a git repo that is located in REPO\_PATH.

I thought maybe I can combine a `cd REPO_PATH` call with above command.

Any ideas how to do that?

---

<div class="post-metadata">

**Author:** ![Sukera](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@Sukera](https://discourse.julialang.org/u/Sukera)\
**Post date:** [August 31, 2018, 12:02pm UTC](https://discourse.julialang.org/t/chain-several-shell-commands-to-get-current-commit-of-git-folder/14359/2 "2018-08-31T12:02:27Z")

</div>

Julia has a git library in the stdlibs:

```julia
julia> using LibGit2

help?> LibGit2.head
  LibGit2.head(repo::GitRepo) -> GitReference

  Return a GitReference to the current HEAD of repo.

  ────────────────────────────────────────────────────────

  head(pkg::AbstractString) -> String

  Return current HEAD GitHash of the pkg repo as a string.

```

Also take a look at this:

[https://docs.julialang.org/en/stable/stdlib/LibGit2/](https://docs.julialang.org/en/stable/stdlib/LibGit2/)
