ssloan ssloan - 1 year ago 64
Git Question

What is the implication of these git commands?

I have a sample jenkins pipeline script which has sections for build, test etc. then a release section which starts with these git commands:

git config remote.origin.fetch +refs/heads/*:refs/remotes/origin/*
git config branch.master.remote origin
git config branch.master.merge refs/heads/master

I'm a git novice so can someone explain what they are doing please? They appear right before the sbt release plugin is used to create a new release (analagous to the maven release plugin).


Answer Source

These commands add or modify lines in the .git/config configuration file for the current working directory, and you can find documentation on these and other settings by running git help config.

In brief, these specific configuration settings are part of what is needed to configure Git so that a git pull will fetch all branches from an origin remote and then, provided the current local branch is master, attempt to merge the remote's master branch into the local master branch. The missing piece is the definition of the origin remote, which must be configured elsewhere.

Note that when you clone a remote repository, these are the default settings automatically set up by Git. (Try it: do a git clone of any remote repository and then inspect your .git/config file, and you'll find the equivalent of these settings in place.) So, it looks like maybe these commands are just ensuring that these defaults are correctly in place prior to running the release scripts.