How to add files to git ?
git status command tells us what is the difference of working directory, staging index and repository. Now, create file second.txt and third.txt trigger command git status
You will see second.txt and third.txt file in untracked section.
You have to add these files so that git will track these files.
git add <file_name> <file_name>
git add .
example: git add second.txt
example: git add third.txt
example: git add second.txt third.txt
example: git add .
These command tells git to add these files to staging directory.
So add second.txt file to staging directory.
git add second.txt
now, fire git status command.
you will see two sections
1) Changes to be commited
2) Untracked files
now commit your changes with following command
git commit -m “second file created in project”
What ever have in staging index is going to be committed. In our case we have second.txt file
It’s going to be committed.
Now, add third.txt file to staging index, commit it.
trigger git status command and then try to view log with git log command.
How to modify files to git ?
1) Now, modify second and third.txt files
same way add these files and commit it and try to view git log.
How to check files difference in git ?
This command gives you all files you have modified with changes
now modify any file and try with git diff command
git diff second.txt (For specific file)
git diff command tell us difference between repository directory and working directory.
Some time you need to see what you made changes in staging directory.
you can do this with following commands
git diff –staged
git diff –cached // runs on lower version of git.
git diff –staged second.txt.
How to remove files from git ?
How to delete files and track those files using git?
suppose you have a file second.txt file and suppose you want to delete that file.
You can do this with following to methods
1) manually delete second.txt file and trigger git status command. This command show you that
you have deleted second.txt file. Now, tell git to remove that file with rm command.
git rm second.txt then commit your changes.
In short, manually delete the file then tell git to remove deleted file, tell git to show status and
then commit your changes
2) second method is very easy way to delete file from git. Just tell git to remove file. Tell git to
show status then commit your changes.
command: git rm <file-name>
command: git status
command: git commit -m “file deleted”
Note: difference is that in first method you have deleted file copy in recycle bin folder. where as
in second method it is completely delete your file.
How to rename your files in git?
Let us see how to track renamed files in git. Like delete/remove we can rename files and track those
files in a git.
1) Go to your directory and make rename the file. open command prompt and trigger git status command.
This command show you file deleted and new file added status.
now, trigger following command
git add <file-name>
git rm <file_name>
2) In second method you can trigger move command (rename your file directly from git)
command: git mv <old-file> <rename-file>
Note: If you have litle changes in a file use second method. If you have lots of changes in your file then use first method.
how to move file in git?
Moving file is like a renaming the file.
Command: git mv <file-name> <destination/file-name>