Reputation: 751
Is there a way to figure out which git branch my local rails server takes all data and structure from?
Let's say I switch to another branch for some reasons while my local rails server is still running. I would like to know which branch was checked out at the moment I started the rails server.
For example, if it happens that I change the branch while the server is still active on another terminal, then I forget to restart the server and I want to try something out on the first branch which is different from the second branch, I would like to know the name of the first branch in order to understand why it behaves differently.
Of course the normal behavior would be to restart the server manually (CTRL+C
+ rails s
) without keeping track of the previous branch name, but you know, you get confused when this happens and you wonder why it's so. Then you might like to know this information (i.e. if that branch differs from you actual one) simply to avoid further headaches...
Upvotes: 2
Views: 2324
Reputation: 751
In the end I ended up putting this in my code (following this post):
in config/application.rb
:
module SoundnotationBackend
class Application < Rails::Application
...
config.after_initialize do
::Git_branch = `git rev-parse --abbrev-ref HEAD`
end
end
end
so I can call the Git_branch
variable anywhere, e.g. in my views/layouts/application.html.erb
:
<% if Rails.env == 'development' %>
<%= Git_branch %>
<% end %>
Upvotes: 5