Lesson 8
Making Objects the Main Star!
Chapter 5: Objectify your robot!
git ignore
Let’s now create a .gitignore
file to ignore any pre-compiled byte codes!
Create a new file in your robot main directory, and call it .gitignore
. Note that there is a dot in front of .gitignore
!
Open this file in a text editor, and add the following lines to it. Save the file.
**/__pycache__
**/*.pyc
The first line tells Git to ignore all __pycache__
directories. The two asterisks (**/
) gets it to ignore any __pycache__
directories recursively, that is, it will ignore subfolder/__pycache__
, subfolder/subfolder/__pycache__
, etc.
Similarly, the second line tells Git to ignore all files ending with .pyc
, in whichever sub(sub)folders in the robot directory.
The Git documentation gives more examples of different patterns that you can include. Obviously, you can just include the file names directly without any patterns.
If you run git status
again, __pycache__/
should no longer be in the untracked files list!
user@MACHINE:~/robot$ git status
On branch main
Your branch is up to date with 'origin/main'.
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: main.py
Untracked files:
(use "git add <file>..." to include in what will be committed)
.gitignore
robot.py
no changes added to commit (use "git add" and/or "git commit -a")
Now, add .gitignore
and robot.py
to your repository, and also add the updated version of main.py
.
user@MACHINE:~/robot$ git add .
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: .gitignore
modified: main.py
new file: robot.py
user@MACHINE:~/robot$ git commit -m "Refactored robot to be a Robot instance."
[main a59b475] Refactored robot to be a Robot instance.
3 files changed, 66 insertions(+), 32 deletions(-)
create mode 100644 .gitignore
create mode 100755 robot.py
You now have added your newly refactored files to your repo, without adding the pre-compiled byte codes!