How to Open a File on Git Bash

John Wachira Feb 02, 2024
  1. Open a File on Git Bash
  2. Conclusion
How to Open a File on Git Bash

We cannot use open in Git Bash. If you try to open a file using open on Git Bash, you’ll get the bash: open: command not found error. This short article illustrates how to open a file on Git Bash for Windows.

Open a File on Git Bash

We can use several commands to open a file on Git Bash. It depends on whether you want to make edits or see the contents of the file.

For example;

If we want to only see the content of our sample.php file, run the following script.

Command:

$ cat sample.php

This should display the content of our sample.php file.

Output:

open a file in git bash

We cannot make edits with the above command.

If we want to make edits, we can use the $ start and $ explorer commands, but they will open the file with your default program.

In our case, we have configured VSCode to open our php files. Hence, when we run the below scripts.

Command:

$ start sample.php

Command:

$ explorer sample.php

Both above commands will open the sample.php file in VSCode.

Conclusion

We’ve discussed how to open files on Git Bash. If you only need to see the content of the file, use the $ cat command, and if you need to make edits, you can use the $ start or $ explorer commands.

Author: John Wachira
John Wachira avatar John Wachira avatar

John is a Git and PowerShell geek. He uses his expertise in the version control system to help businesses manage their source code. According to him, Shell scripting is the number one choice for automating the management of systems.

LinkedIn

Related Article - Git File