Bruce Irvine
Bruce Irvine

Reputation: 119

How can I make a text file in git-bash?

How can I make a text file in Git-bash and then how do I go into that file and add text?

Upvotes: 11

Views: 85535

Answers (6)

Viraj Dilshan
Viraj Dilshan

Reputation: 1

  1. First of all open the folder you want to create the new file in your text editor like 'brackets' or 'VS studio'.

  2. Then simply type touch newFile.txt in git-bash.

  3. Then go back to text editor you have previously open and you can see the newFile.txt appears in the open folder.

Then you can easily edit that file inside your text editor.

Upvotes: 0

Anga
Anga

Reputation: 2641

Use this code to open a new text file

subl newFile.txt

Here subl represents sublime text, my default text editor, and newFile.txt is the new file I want to create and edit. git-bash opens the new file in you default text editor. You can edit and save from there, or just save

To add the new file to stage use this code

git add newFile.txt

ant to commit to your reposiory, use this code

git commit

Upvotes: 0

user7123229
user7123229

Reputation:

You can use the echo command. Enter the following line into your command prompt to create a new file with the required content:

echo "Put any content here" >> Newfile.txt

If the command line doesn't return any message, this means that you created the file correctly.

The message in between the double quotes will be the content of the new file.

Upvotes: 6

CodeWizard
CodeWizard

Reputation: 142084

if you are using git bash (or terminal under unix/mac) you simply have to type echo 'text...' >> file_name.

if you are no windows machine and you try to do it from cmd its much better to simply create the file with windows explorer.

Upvotes: 0

SVTAnthony
SVTAnthony

Reputation: 461

There are many ways to create a file using BASH.

using touch touch newFile.txt only creates.
using echo echo > newFile.txt only creates.
using cat cat > newFile.txt creates and can start appending to file.
using vim vim newFile.txt creates and can start editing the file.

Also the .txt extension is only for convenience and categorization. Some editors view the extension to format the data, but for a txt there's no differnce.

After creating the file, add it to the git repository.

git add newFile.txt
git commit -m "added new file"

Upvotes: 18

VonC
VonC

Reputation: 1324168

In bash alone, you can simple use echo (to initialize it) and vi (to edit it)

echo Text example> aNewFile.txt
vi aNewFile.txt
git add aNewFile.txt
git commit -m "Add aNewFile.txt"

Depending on your environment, you can setup other editors, but in a Windows Git bash, vi is the default one.

Upvotes: 1

Related Questions