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 logsand then a series of heroku commands on my master branch only to continuously get information about my staging environment. No amount ofheroku logs -r productionwould 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
urlfor 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
Top comments (5)
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
~/.gitconfigThanks 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/configfile?What are the options under each item?
What is the difference between merge and fetch?
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.
git fetchmeans "go to the remote repository and download the new changes to our local repository".git mergemeans "integrate this set of changes into this other branch".git pullmeans more or less "go to the remote repository, download the new changes, merge such changes in the branch" (git fetch + git merge)Thank you for breaking this down for me. Awesomely detailed and helping me understand.
You deserve a sticker!!!