gitversion-controlbranchgit-branch

View a file in a different Git branch without changing branches


Is it possible to open a file in a git branch without checking out that branch? How?

Essentially I want to be able to open a file in my GitHub Pages branch without switching branches all the time. I don't want to modify it, just want to view it.


Solution

  • This should work:

    git show branch:file
    

    Where branch can be any ref (branch, tag, HEAD, ...) and file is the full path of the file. To export it you could use

    git show branch:file > exported_file
    

    You should also look at VonC's answers to some related questions:

    UPDATE 2015-01-19:

    Nowadays you can use relative paths with git show a1b35:./file.txt.