Advertisement
Guest User

Display the Name of Current Git Branch

a guest
Feb 5th, 2016
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. http://www.experts-exchange.com/questions/28922922/Display-the-Name-of-Current-Git-Branch.html
  2. Experts exchange :
  3. Display the Name of Current Git Branch
  4. Question by: Ray Paseur On 2016-02-01 10:12 PM Views 25
  5. I would like to be able to use PHP to display the name of my current branch. What would be a good way to discern and display which Git branch I'm currently using?
  6.  
  7. One thought that has occurred to me would be to place a "branch-name" file in each branch, and display the information from that file. Has anybody tried something like this? Does it seem feasible?
  8.  
  9. Thanks!
  10. Git Version Control Programming Web Development PHP
  11. Good Question?
  12. Request Attention
  13. COMMENTS
  14.  
  15. Fouad Maidine
  16. Accepted Solution 2016-02-01 at 22:28:11ID: 41444176500
  17. Comment Utility
  18. In 2 lines ^^
  19. $root='.git/HEAD' ;
  20. $name= implode('/', array_slice(explode('/', file_get_contents($root)), 2));
  21.  
  22.  
  23. 1:
  24. 2:
  25. Select all
  26. Open in new window
  27.  
  28.  
  29. I do not know if it's the best way to do this but it works
  30. Good Solution? 1
  31.  
  32. Ray Paseur
  33. Author Closing Comment 2016-02-02 at 16:06:31ID: 41445360
  34. Works beautifully! Thanks, ~Ray
  35. Good Comment?
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement