Python para Data Science e Analytics
Python para Data Science e Analytics › Guides › How to use Git in a data science project

How to use Git in a data science project

To use Git in a data science project, create the repository with a .gitignore before the first commit, clear notebook outputs, and keep large data, credentials, and binary models out of history. Short branches, small commits, and a sample-data folder make the workflow easier to review. The Python for Data Science and Analytics course, from beginner to advanced, includes a machine learning project, exercises, a certificate, and permanent access, so Git practice fits the portfolio work it covers.

Topics: git, versionamento, portfólio

Why version a data science project with Git?

Git records changes to text files: scripts, configuration, README, and notebooks. In data science, it lets you return to an earlier version of an analysis, compare experiments, and explain how a result was produced.

Notebooks and models need extra care. A notebook saves outputs and execution counters, which can make history noisy. Raw data and trained models are often too large for a repository.

How do you set up the repository before the first commit?

Start with a project folder and run `git init`. Before adding files, create a `.gitignore` with virtual environment folders, cache, Jupyter checkpoints, and raw data. That prevents clutter in the first commit.

The README should state what the project does, where the data comes from, how to reproduce the environment, and which results are expected. If you need a small sample for tests, keep it in `data/sample/` and leave the full dataset out of Git.

A dependency file such as `requirements.txt` or `environment.yml` helps another person rebuild the environment without committing the environment folder itself.

How do you version notebooks without cluttering history?

Clear outputs before each commit. In Jupyter, use Cell > All Output > Clear; tools such as nbstripout can also remove outputs automatically. The notebook stays under version control, but the diff remains readable.

Separate exploration from reusable code. Repeated functions belong in `.py` files under `src/`. Name notebooks by stage, such as `01_exploration.ipynb` and `02_modeling.ipynb`, instead of creating `analysis_final_v3.ipynb`.

Large printed tables and charts inside a notebook are hard to review in a diff. Keep the code that produces them and store final figures outside the notebook when the figure is an output, not a source file.

How do you handle data and models in Git?

Large raw data, personal data, and frequently updated datasets should not enter the repository. If you need to version large data, consider Git LFS or DVC, keeping only configuration and the sample needed to test the pipeline in Git.

Trained models also should not go into history as binaries. Store code, hyperparameters, seeds, metrics, and the data version used for training. The model file can live in artifact storage, outside Git.

In the course's final project, which runs exploratory analysis and machine learning end to end, the repository can hold clean notebooks, scripts, and README. Data and models stay in ignored folders or external storage. The course page at python.paanalytics.net describes the full module path and the project format.

What should not go into the repository?

Credentials are the most critical item. Passwords, tokens, and API keys must never be committed. If a secret enters history, revoke the key and remove the file from history; deleting it in the next commit is not enough.

Large datasets, personal data, virtual environments, and binary models also stay out. The table below summarizes the practical rule for deciding what goes into Git and what does not.

How do you close the cycle with branches, commits, and review?

Use the main branch for the stable version. Create short branches for an experiment, a cleaning step, or a model change. Open a pull request even when you work alone; it creates a place to review the diff and record why the change exists.

Keep commits small and messages specific. A commit that changes cleaning, feature selection, and model parameters at once is hard to review and hard to revert. Before merging, check that notebooks are clean, no secrets are staged, and the README still matches the project.

ItemCommit to Git?Reason
Scripts and READMEYesText files that explain and reproduce the analysis.
Clean notebooksYesUseful for review when outputs are cleared.
Small sample dataYes, if non-sensitiveUsed for tests; keep it small and documented.
Raw or large datasetsNoHeavy and often not reproducible in a repository.
Personal dataNoPrivacy and compliance risk.
`.env`, tokens, passwordsNoSecrets must never enter history.
`.pkl`, `.joblib`, `.h5` modelsNoBinary artifacts belong in artifact storage.
Virtual environments and cacheNoRecreated from dependency files.

This table is a decision guide from the workflow on this page; it does not use third-party benchmarks.

Explore the Python for Data Science and Analytics course

Secure payment via Hotmart, up to 12 installments.

Enroll now Product site

Frequently asked questions

Can I use Git if I only work in Jupyter Notebook?

Yes. Clear outputs before committing and keep reusable functions in `.py` files. The notebook remains useful for exploration, while scripts make review and reuse easier.

Should I commit the full dataset to Git?

Usually no. Keep raw or large data out of Git, and commit a small non-sensitive sample under `data/sample/` if tests need it. For large data that must be versioned, use Git LFS or DVC.

How often should I commit in a data science project?

Commit small logical changes, such as one cleaning step or one model configuration. Avoid mixing notebook output cleanup, code changes, and data configuration in a single commit.

How does this Git workflow connect to the course project?

The Python for Data Science and Analytics course closes with an end-to-end exploratory analysis and machine learning project. A clean repository with scripts, clean notebooks, and a README can present that work as part of a portfolio; data and binary models stay outside Git.

Does the course require prior programming knowledge?

No. The course is designed from beginner to advanced and does not require prior programming knowledge. It covers IDE and Jupyter Notebook setup, Python basics, NumPy, Pandas, data cleaning, visualization, machine learning topics, and a final project.

Ler em português →