In this post, I am going to explain how to check the
status of your files in git repository using ‘git status’ command.
Create a repository
Create a directory HelloWorld and execute 'git init'
command to make this as a git repository.
C:\Users\Public\gitDemos\HelloWorld>git init Initialized empty Git repository in C:/Users/Public/gitDemos/HelloWorld/.git/
When you execute the command ‘git status’, you can see
below kind of messages.
C:\Users\Public\gitDemos\HelloWorld>git status On branch master No commits yet nothing to commit (create/copy files and use "git add" to track)
As you see the above messages, git is saying that you are
in master branch and no commits are happened yet.
Add new file to the
HelloWorld repository
Create a file ‘readMe.txt’ in the HelloWorld repository.
Execute ‘git status’ command.
C:\Users\Public\gitDemos\HelloWorld>git status On branch master No commits yet Untracked files: (use "git add <file>..." to include in what will be committed) readMe.txt nothing added to commit but untracked files present (use "git add" to track)
As you see above output, git says, there is one untracked
file readMe.txt.
Untracked file: Untracked
file is the one, which is not in previous snapshot. To track the untracked
files, you need to run ‘git add <FILE_NAME>’ command.
Tracking New files
Use the command 'git add <FILE_NAME> to track the
untracked (or) new files.
C:\Users\Public\gitDemos\HelloWorld>git add readMe.txt C:\Users\Public\gitDemos\HelloWorld>git status On branch master No commits yet Changes to be committed: (use "git rm --cached <file>..." to unstage) new file: readMe.txt
As you see above snippet, I asked git to track the file
‘readMe.txt’ using add command. When I execute ‘git add’ command, it is moved
to staging area.
Committing your
changes
Execute the command ‘git commit’ to commit the changes to
git repository.
When you execute ‘git commit’ command, it opens an editor
of your choice (At the time of git installation, you can specify this).
Enter some information like ‘Adding readMe.txt file to
HelloWorld repository’
Save the commit message (CTRL + S).
Close the editor.
You can see below messages in console.
C:\Users\Public\gitDemos\HelloWorld>git commit [master (root-commit) f1763f8] Adding readMe.txt file to HelloWorld repository 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 readMe.txt
No comments:
Post a Comment