DEV Community

Jess Chandler
Jess Chandler

Posted on

Explain git config Like I'm Five

I felt like I totally understood when I set up my git config for an app running on heroku to finally have a staging and production environment separately. However, it has been a few months since I did it, and now things are not working as I thought they would. Clearly, I did not understand at all.

Essentially, I wanted to have a heroku staging app (generic heroku url) and my heroku production app (at my url) where I can get logs for both and manage both through the heroku CLI on my terminal. This seems like a fairly typical need, and I expect I'm not alone in getting confused.

Here's where I'm at:

  • I followed Heroku dev guidance to setup my environment... I think
  • Everything was working smashingly. My master pushes went to my github repo and were automatically deployed on my production heroku app. My staging pushes went directly to my heroku staging app.
  • I was concerned about an issue and ran heroku logs and then a series of heroku commands on my master branch only to continuously get information about my staging environment. No amount of heroku logs -r production would change this situation.
  • In an attempt to get logs from my production app, I ran heroku git:remote -a appname -r production. Sadly, that changed my production pointer from my github repo back to heroku (which expected to get code from github).
  • I manually changed the url for my production remote back to github in my git.config. Now, changes push properly to github again, but I cannot see production heroku logs using the CLI.

How is this so confusing? I tried a ton of googling for guidance git-config but encountered explainer after explainer just going step by step through typing shell commands to set things up and not really discussing WHAT IN THE WORLD is going on inside the .git/config file.

I appeal to my amazing DEV.TO friends for help here. Explain this whole .git/config to me like I'm 5.

FWIW - mine looks something like:

[core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
    ignorecase = true
    precomposeunicode = true
[branch "master"]
    remote = production
    merge = refs/heads/master
[remote "heroku"]
    url = git@heroku.com:myapp.git
    fetch = +refs/heads/*:refs/remotes/heroku/*
[remote "production"]
        url = https://github.com/me/myapprepo.git
    merge = refs/heads/master
[remote "staging"]
    url = https://git.heroku.com/adjective-noun-number.git
    fetch = +refs/heads/*:refs/remotes/staging/*
[heroku]
    remote = staging
[push]
    default = tracking
Enter fullscreen mode Exit fullscreen mode

Top comments (5)

Collapse
 
rhymes profile image
rhymes •

Hi, Jess.

Judging from file you have three remotes set: heroku, github/production and github/staging

Your branch is tracking the master branch of the github/production repo.

Heroku points to your staging environment.

Going back to the config file, there's nothing magical to it. It's what the name say: the configuration of your git repository.

Every repo has one, you sometimes also have a global one in ~/.gitconfig

Collapse
 
jessachandler profile image
Jess Chandler •

Thanks for the response. I know it is not magical.

What is not clear to me is how I would be confident what each of the things means.

For example,
What commands can be in a .git/config file?
What are the options under each item?
What is the difference between merge and fetch?

Collapse
 
rhymes profile image
rhymes •

Keep in mind that practically always you don't edit the gitconfig file manually, but trough git config.

This is a good tutorial.

If you want to know each and every option the gitconfig can have you have to read the documentation.

What is the difference between merge and fetch?

git fetch means "go to the remote repository and download the new changes to our local repository". git merge means "integrate this set of changes into this other branch". git pull means more or less "go to the remote repository, download the new changes, merge such changes in the branch" (git fetch + git merge)

Collapse
 
jessachandler profile image
Jess Chandler •

Thank you for breaking this down for me. Awesomely detailed and helping me understand.
You deserve a sticker!!!