githubNotes-1
githubNotes-1
Stage files
Commit
➔ Working directory is a workplace where we are simply making our
project files.
➔ Staging area contains files that we want to commit
For Example: If you create a project which contains following files
Index.html, script.js, style.css
If you want to improve your project by changing in each file (modify
source code) and create version 2 of your project. But here you find bug
in script.js and you want to keep changes made in index.html and
style.css you can put both files in staging area and continue to modify or
resolve script.js
➔ Those files you want to take in next commit you can put it in staging
area.
Now once your directory become git directory you can also make it normal
directory by writing following command
rm -rf .git
when you initialize your directory as git repository it will create one hidden
folder named .git which contains all the information of the directory and all the
snapshots of the directory.
By writing above command, you are removing that file forcefully.
Note: But be careful while writing this command. It will clear all he commits
and trace of your directory and won’t trace anything, you may lose your
important commits also.
Commit
➔ First time when you check directory status exactly after creating git
repository, all the files are ‘untracked’.
➔ When you add files for first time it will become ‘unmodified’. Which
indicates that tracking of files now started. If you modify any file you will
show the ‘modify’ status.
➔ All the file you put in the staging area would be marked as ‘A’ means
added in staging area.
➔ And after the commit snapshot of your repository would be taken and all
the marks would be removed. Which means it is marked as ‘unmodified’
by git. Again, you make any change after commit it would marked as
‘modified’
➔ In visual studio code you will see the character sign following the file
name which indicates as follows:
U: Unmerged/ Untracked
A: Addition of the file
D: Deletion of the file
M: Modified the file
R: Renamed the file
T: Changed the type of the file
Git would not trace /node_module folder and all the files which
extension is .exe
- In other case, if git is currently tracking your file and certainly you
want that this file should not be tracked by git, Then you cannot
directly write the name of the file in .gitignore file , you have to first
make it untracked by writing following command .
- You can directly ignore that files only which are untraced by git. So,
for ignoring files which are already tracked by git you first have to
untracked it.
git rm --cached <filename>
git rm --cached hello.exe
• Branches in git
When you are developing any application by collaborating on same project
you may not want to risk original production reside on main/master branch.
Any developer can create the branch and work only on that branch, after that
if manager or leader of the project found that changes made on different
branch is considerable then he/she can merge the branch to the main/master
branch or can discard the changes by deleting the branch.
Commands Description
git checkout -b <branch_name> Create the new branch of given name.
git checkout -b myBrc i.e: Create a new branch by the name of
myBrc
git checkout <branch_name> Switch to the desire branch.
git checkout master i.e: Switch to the master branch
git branch Display list of the branch, and marked
current branch as asterisk
git branch -d <branch_name> Delete the branch which is already pushed
or merged
git branch -D <branch_name> Forcefully delete the branch even if its not
merged yet.