Add and Commit
<aside>
<img src="https://prod-files-secure.s3.us-west-2.amazonaws.com/2ba07339-dd53-47ac-b00d-c83e7722c42d/b39e600d-15ce-44a6-b5ce-eb6490d84e29/Colorful_Illustrative_Young_Male_Avatar_(1).png" alt="https://prod-files-secure.s3.us-west-2.amazonaws.com/2ba07339-dd53-47ac-b00d-c83e7722c42d/b39e600d-15ce-44a6-b5ce-eb6490d84e29/Colorful_Illustrative_Young_Male_Avatar_(1).png" width="40px" /> Git add
and Git Commit
For instance:
Creating a new file for python.
The status of git
On branch main
Your branch is up to date with 'origin/main'.
Untracked files:
(use "git add <file>..." to include in what will be committed)
learning_git/
nothing added to commit but untracked files present (use "git add" to track)
It is being said that the file is untracked which means we need to add that.
Git add
C:\\Users\\60115\\Documents\\Study\\Business Intelligence, Data Scientist, Data Analyst and Data Engineers\\Business Intelligence Analyst\\Python\\Python-Learning>git add py
thon.py
It seems when we are adding Git add
there are no changes. However, when we check it, we will see that a file has been just added into directory. Unless we use git status
, then it will appear.
C:\\Users\\60115\\Documents\\Study\\Business Intelligence, Data Scientist, Data Analyst and Data Engineers\\Business Intelligence Analyst\\Python\\Python-Learning>git add py
thon.py
C:\\Users\\60115\\Documents\\Study\\Business Intelligence, Data Scientist, Data Analyst and Data Engineers\\Business Intelligence Analyst\\Python\\Python-Learning>git status
On branch main
Your branch is up to date with 'origin/main'.
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
new file: python.py
Untracked files:
(use "git add <file>..." to include in what will be committed)
learning_git/
It means our file named “python.py” has been added into “Staging Area.”
C:\\Users\\60115\\Documents\\Study\\Business Intelligence, Data Scientist, Data Analyst and Data Engineers\\Business Intelligence Analyst\\Python\\Python-Learning\\learning_git\\Fundamental-Python-Learning>git commit -m "my first test"
[main f4e68f6] my first test
1 file changed, 2 insertions(+)
create mode 100644 test_python.py
Adding file one by one
C:\\Users\\60115\\Documents
\\Study\\Business Intelligence, Data Scientist,
Data Analyst and Data Engineers\\
Business Intelligence Analyst\\Python
\\Python-Learning\\learning_git\\
Fundamental-Python-Learning>
git add file_one.txt file_two.txt
Adding file all immediately
C:\\Users\\60115\\Documents\\Study\\
Business Intelligence, Data Scientist,
Data Analyst and Data Engineers\\
Business Intelligence Analyst\\Python\\
Python-Learning\\learning_git\\
Fundamental-Python-Learning>git add .
Check Status
C:\\Users\\60115\\Documents\\Study\\Business Intelligence, Data Scientist, Data Analyst and Data Engineers\\Business Intelligence Analyst\\Python\\Python-Learning\\learning_git\\Fundamental-Python-Learning>git status
On branch main
Your branch is ahead of 'origin/main' by 1 commit.
(use "git push" to publish your local commits)
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
new file: file_one.txt
new file: file_two.txt
Commit to Input in Local Repo
Let’s say we got another 2 files to add. file_one.txt and file_two.txt.
Letter U in the very right side → refers to “Untracked.”
We can basically add file one by one.
It is useful when we just want to commit some additional files.
While the other files are irrelevant.
Or when we are working on a file and the other has not yet finished.
Using Git add .
to add entire files in this repo to update all.
Let’s check it.
As we can see here, changes have been committed.
All of new files aside of file**test_python.py
** is added.
However, these 2 files are in still “Staging Area.”
<aside>
<img src="https://prod-files-secure.s3.us-west-2.amazonaws.com/2ba07339-dd53-47ac-b00d-c83e7722c42d/b39e600d-15ce-44a6-b5ce-eb6490d84e29/Colorful_Illustrative_Young_Male_Avatar_(1).png" alt="https://prod-files-secure.s3.us-west-2.amazonaws.com/2ba07339-dd53-47ac-b00d-c83e7722c42d/b39e600d-15ce-44a6-b5ce-eb6490d84e29/Colorful_Illustrative_Young_Male_Avatar_(1).png" width="40px" /> Basically, it’s same step as previous commit. It is advisable to not naming a file with space. For example, Machine Learning.py
it can be unreadable. Instead, it’s better to use Machine_Learning.py
</aside>
Staging Area