Git Github GitIgnore

2 min read

I make mistakes, hopefully you too. That's what makes us more Human :D

While building a software, there will be n number of times when we build something and it has bug or we need to revert to the previous version of code. For this reason we are going to use a tool named GIT. You can get GIT from here: https://git-scm.com/downloads

Just go with the default settings and install it. Once its installed, In a new terminal type: 

PS C:\Users\soura\Documents\mine\fastapi\blog> git --version
git version 2.49.0.windows.1

Now, we can create a github repository (a type of google drive to store codebase but much more powerful).  Visit: https://github.com/new and create a new repository.

Once its created, Github will guide us on how to push our code from our local system to Github. 

Let us try the commands one by one:

git init
git status

At this point notice the files which are about to be pushed to github. If you have created a vitual environment it will be pushed to github. Which is absolutely not needed. Or even worse, if we keep our secret api keys in some .env file or secrets file it will be pushed to github. Which can be a security vulnerabilty nightmare. To prevent it, we can utilize a file named .gitignore 
The files and folders specified in .gitignore will be ignored by git and not pushed to github. 

# Environment Variables
.env
.env.local
.env.production

# Python
__pycache__/
*.py[cod]
*$py.class
*.so
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg

# Virtual Environment
venv/
env/
ENV/
.venv/
.env/

# IDE
.vscode/
.idea/
*.swp
*.swo
*~

# Database
*.db
*.sqlite3
*.sqlite

# Logs
*.log
logs/

# Testing
.pytest_cache/
.coverage
htmlcov/
.tox/

# OS
.DS_Store
Thumbs.db

# FastAPI specific
*.pid
instance/
.webassets-cache

Now, if we again type git status, We will notice that this time the env folder or .env file if any will be ignored. Once we are sure that only the required files are to be pushed, We can add the files to be pushed to a staging are or pre-commit area. The green colored files are about to be committed and pushed to github.

Okay, now we can commit and push. We should always give a meaningful commit message and push our code to Github. 

git commit -m "initial project configuration"
git branch

#rename the branch name to be 'main'
git branch -M main
git remote add origin [email protected]:yourgithub/blog-fastapi.git
git push -u origin main

FastAPITutorial

My priority is to help build a production-ready application using FastAPI

I prioritize quality over simplicity. Our challenging approach ensures you're prepared for real-world development.

Contacts

Refunds:

Refund Policy
Social

Follow us on our social media channels to stay updated with our latest tutorials and resources.

© Copyright 2022-2025 Team FastAPITutorial. All rights reserved.