1

I am developing an API client, and being a good git user I did all my work on a feature branch. I made dozens of commits to my local branch but have not pushed it anywhere. I am now ready to merge my local branch into master

However during initial testing I had my API key in code which was then committed to my local feature branch. I've since fixed this and the current version of all code on my feature branch uses config files and has no sensitive information.

If I squash merge my feature branch into master (with git checkout master; git merge--squash my-feature) and push that, will the secret API key that was committed earlier and then fixed be visible by others? Or will squashing the commits render the secret unusable to anyone who doesn't have my local branch?

Josh
  • 10,961
  • 11
  • 65
  • 108
  • 1
    As long as you never pushed the feature branch, those files never got into the remote. – matt Jan 28 '20 at 20:52

1 Answers1

1

Yes, if you squash all the intermediate commits, the secret will not be visible in the pushed branch. You should rebase, not merge, though.

JoelFan
  • 37,465
  • 35
  • 132
  • 205
  • Thanks. Not sure why I should rebase, however. I crated a branch off `master` and I'm done with my branch, I now want to get my work back in to `master` to share with others. You're suggesting a rebase, not a merge, for that? – Josh Jan 28 '20 at 20:52
  • @josh, it avoids an unnecessary merge commit. To be honest I haven't done merge squash... I always rebase -i and do the squash that way. – JoelFan Jan 28 '20 at 20:59
  • Ah. Yeah in this case I *want* the merge commit as the commit where my new feature is added. Which is why I made a feature branch for it :) Thanks for the help! – Josh Jan 28 '20 at 21:01