Execute the following commands. Open Git-Bash or Linux/Mac Terminal
touch 4.txt
echo "Hello" >> 1.txt
The above commands create a new file which is not in local repository and modifies a file which is already in local repository
Now Execute git status and the following output will be shown
On branch master
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: 1.txt
Untracked files:
(use "git add <file>..." to include in what will be committed)
4.txt
no changes added to commit (use "git add" and/or "git commit -a")
Untracked file is a new file which has no history in local repo. Modified file is existing file which has history in local repo.
Add only modified file to staging area
git add --help
git add -u
git status
Now add the untracked file to staging area and commit the changes to local repo.
If you want add all the changes at once to staging Area
git status
git add -A
# or if you are in top folder on git repo
git add .
git status
git commit -m "Fourth Commit"
ignoring some directories and files
Execute the following commands
mkdir bin
touch bin\10.txt
touch 7.txt
echo "hello" >> 6.txt
We want everything in bin folder to be ignored. Now execute git status and the following o/p will be shown
On branch master
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: 6.txt
Untracked files:
(use "git add <file>..." to include in what will be committed)
7.txt
bin/
no changes added to commit (use "git add" and/or "git commit -a")
Git has a way to ignore certain files/foders. For that create a file called as .gitignore in the repository root.
touch .gitignore
Now add bin/* to the .gitignore file and execute the following
git status # no bin/ information should be shown
git add .
git commit -m "Fifth Commit"
git status
git log
Moving Changes from Staging Area to Working Tree
Reset command can help in doing this
Execute the following command
touch 8.txt
touch 9.txt
touch 10.txt
echo "hello" >> 7.txt
git status
git add .
git status
Now move 10.txt from staging area to working tree
git reset 10.txt
git status
Now if you want to remove all the changes in staging area and modified changes in working tree
git reset --hard
git status
To remove all the untracked files from working tree