2

I would like perform certain steps in a pipeline script only if my local branch's file is different from the remote's file.

Locally, I can use:

git diff HEAD:file.txt origin/master:file.txt

This does not work from within my CICD pipeline because I need to authenticate to my bitbucket repo.

Is there a way to pass authentication information (either in URL form like for git pull/push) or is there a different way of passing authentication when using git diff command?

2
  • 1
    head (lowercase) vs HEAD (uppercase).
    – phd
    Commented May 20, 2020 at 16:01
  • 2
    Thanks. I updated my question with capital, since that seems to be the correct syntax. Although lower or upper case doesn't seem to make a difference for cli command results locally.
    – kravb
    Commented May 20, 2020 at 17:04

1 Answer 1

2

git diff does not need any authentication data: it is purely a local operation within the repository.

You might need authentication when doing a git fetch, to refresh the remote origin, if it is a private repository.
But not for git diff.

For example, regarding a BitBucket pipeline, you can add SSH keys.

I though git fetch downloads the remote branches?

Check your local config for the remote "origin"

git config remote.origin.fetch

If you see the refspec

+refs/heads/*:refs/remotes/origin/*

Then you would fetch all branches.

But if you see only uat/xxx branches, then maybe you don't have a remote named "origin" at all (see git remote -v)

4
  • Thanks. I tried to do a git fetch to get all repo information. However, when executing git branch -a, there were no new branches, even though fetch showed * branch uat/UAT -> FETCH_HEAD ( which I assume means success). I though git fetch downloads the remote branches?
    – kravb
    Commented May 20, 2020 at 16:48
  • @kravb I have edited the answer to address your comment/question.
    – VonC
    Commented May 20, 2020 at 17:35
  • git remote -v points to the url of my repository. However, git config remote.origin.fetch shows only the local branch and remote branch. This may be the way bitbucket build containers are designed to work. It seems the container is only aware of the branch being worked on and not the entire repository. Would you say that is accurate based on the information?
    – kravb
    Commented May 20, 2020 at 20:34
  • @kravb Yes, but if you modify the refspec to +refs/heads/*:refs/remotes/origin/*, then a git fetch would get all the remote branches.
    – VonC
    Commented May 20, 2020 at 22:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.