- Clone a repository to get a local copy of the code on your machine.
git clone <repository-url>
cd <repository-directory>
- Replace
<repository-url>
with the actual URL of the repository.
- Update your local copy to ensure it's synchronized with the main branch.
git pull origin main
- Replace
main
with the name of your primary branch if different.
- Create a new branch for feature development or bug fixing.
git branch feature-branch
- Switch your working directory to the new branch.
git checkout feature-branch
- Or create and switch in one step:
git checkout -b feature-branch
- After making changes, add them to the staging area and commit. Use clear, descriptive commit messages:
git add .
git commit -m "feat: add new feature for data processing"
- Best Practice for Commit Messages:
- Use prefixes like
feat:
for features,fix:
for bug fixes,refactor:
for code restructuring,docs:
for documentation updates, etc. - Example:
git commit -m "fix: resolve edge case issue in metric calculation"
- Use prefixes like
- Specify files and directories to be ignored by Git.
# Example .gitignore content
.idea/
*.pyc
- Save and commit the
.gitignore
file.
git add .gitignore
git commit -m "chore: add .gitignore file"
- Push your committed changes to the remote repository. Specify the branch name:
git push origin feature-branch
- Open a pull request from your feature branch to the main branch for code review and merging.
- Switch to the main branch.
git checkout main
- Pull the latest changes from the remote main branch.
git pull origin main
- Checking Status: Use
git status
to see the status of your changes and ensure everything is tracked correctly. - Staging Area: Understand the importance of the staging area (
git add
) as an intermediate step before committing changes (git commit
). - Commit Message Standards: Maintain a consistent format for commit messages, using imperative mood and concise descriptions.
- Branch Management: Use
git branch
to list branches,git branch -d branch_name
to delete branches, andgit branch -r
to list remote branches. - Undoing Changes: Use
git revert <commit-hash>
to undo specific changes without rewriting commit history, orgit reset
for more drastic changes. - Tagging Releases: Use
git tag -a v1.0 -m "Initial release"
to create annotated tags for releases. - Rebasing and Merging: Use
git pull --rebase
to integrate changes without creating merge commits orgit merge
to combine branches.
- Download VS Code: Download Visual Studio Code from the official site.
- GitHub Account: Ensure you have a GitHub account for version control and collaboration.
- Create and activate a Python virtual environment:
python -m venv venv_name
source venv_name/bin/activate # On Windows use `venv_name\Scripts\activate`
- This keeps dependencies isolated and your project environment clean.
- Navigation:
- Change directory:
cd <directory>
- Move up one directory:
cd ..
- Change directory:
- Git Operations:
- Check status:
git status
- Add changes to staging:
git add .
or specify a path:git add <path>
- Commit changes:
git commit -m "feat: add new API endpoint"
- Push changes:
git push origin branch_name
- Pull changes:
git pull origin branch_name
- Rebase to update:
git pull --rebase
- Create a branch:
git branch branch_name
- Switch to a branch:
git checkout branch_name
- Fetch all branches:
git fetch --all
- Clone a repository:
git clone <repository-url>
- Check status:
- Tree View:
- On Windows, use
tree /F
to see a tree representation of directories and files.
- On Windows, use
- Python Package Management:
- Install packages:
pip install -r requirements.txt
- Freeze dependencies:
pip freeze > requirements.txt
- pipreqs How?
pip install pipreqs
,pipreqs . --force
- Show installed packages:
pip show <package>
- Install packages:
- Project Files:
main.py
README.md
.gitignore
LICENSE
requirements.txt
- Modules and Imports:
- Organize your code into modules and use
__init__.py
to make them importable. - Example structure:
project/ βββ main.py βββ app/ β βββ __init__.py β βββ backend.py βββ tests/ β βββ __init__.py β βββ test_backend.py βββ requirements.txt βββ .gitignore βββ README.md
- Organize your code into modules and use
- Project Setup:
- Open a folder and navigate to your project directory: `cd <project
-directory>`.
- Clone the repository:
git clone <repository-url>
. - Environment and Git Operations:
- Create and activate the environment.
- Check status:
git status
. - Make changes, save, and commit:
git add . git commit -m "feat: add initial setup for Streamlit app"
- Push changes:
git push origin branch_name
. - Verify changes on GitHub and ensure they align with the latest code base.
- VS Code Extensions and GUI: Leverage extensions for Python, GitLens, Docker, and Streamlit to enhance your coding experience.
- Automate Requirements Management: Use pipreqs or pip-tools for generating and managing
requirements.txt
files. - Working with Forks: Understand forking on GitHub, managing upstream changes, and contributing back with pull requests.
- Ubuntu and WSL: Utilize Ubuntu or Windows Subsystem for Linux (WSL) for a Linux-like development environment on Windows, enhancing command-line operations and development workflows.
- Git Commands and Workflows: Learn more about Git commands and workflows from the official Git documentation.
- VS Code Tips: Explore VS Code tips and tricks to boost your productivity from the VS Code documentation.
- Python Virtual Environments: Understand virtual environments and package management from the Python documentation.