Track a New Project with Git
Level: Beginner · Time: 25–35 min · Category: Version control
Tags: Git · Version control · Prompting
Put a new project under version control with Git: initialize a repository, make clean commits, ignore files you should not track, review history, and push to a remote. Use AI coding assistance to explain commands and draft clear commit messages as you go.
This tutorial assumes you can open a terminal. It uses a small throwaway project so you can practice the workflow safely before applying it to real research code.
Prerequisites
- LLM API Guide — set up AI coding assistance so you can ask it to explain command output and diffs.
- Git installed — check with
git --version. If it is missing, install it from git-scm.com. - VS Code (recommended) — its built-in Source Control panel handles Git with buttons, so most people never need to memorize the commands.
- A remote account (optional) — a GitHub or GitLab account for the final push step.
What you will do
- Confirm Git is installed and set your identity.
- Initialize a repository in a project folder.
- Stage and commit changes with clear messages.
- Ignore files that should never be tracked.
- Review history and undo mistakes safely.
- Push your project to a remote.
Build it step by step
VS Code has Git built in — most people never touch the raw commands. Open the Source Control panel (the branch icon in the Activity Bar, or Ctrl+Shift+G / Cmd+Shift+G) to stage, commit, branch, and push with buttons. Each step below shows the command line first, followed by the In VS Code equivalent. You can also paste any command into VS Code's integrated terminal (Ctrl+`).
1. Confirm Git is installed and configured
Git records who made each commit, so set your name and email once per machine. These values appear in your commit history.
git --version
git config --global user.name "Your Name"
git config --global user.email "you@example.com"
- Use the same email as your remote account (GitHub/GitLab) so commits link to your profile.
- Ask the assistant to explain any
git configoption you are unsure about before changing it.
2. Initialize a repository
Create a small project folder and turn it into a Git repository. git init creates a hidden .git folder that stores the full history.
mkdir git-practice
cd git-practice
git init
echo "# Git Practice" > README.md
git status
git status is the command you will run most. It shows what has changed and what is staged for the next commit.
Open the Source Control panel and click Initialize Repository. VS Code creates the .git folder and lists your files under Changes.
3. Make your first commit
Staging (git add) selects what goes into the next snapshot. Committing (git commit) saves that snapshot with a message.
git add README.md
git commit -m "Add project README"
Write commit messages that explain why a change was made, not just what changed. A good pattern is a short summary line under ~50 characters.
Ask your AI assistant:
I staged these changes with `git diff --staged`. Suggest a clear, conventional
commit message (a short summary line and, if useful, a short body explaining why).
In Source Control, hover a file under Changes and click + to stage it (or stage everything from the Changes header). Type your message in the box at the top, then click the ✓ Commit button.
4. Ignore files you should not track
Some files should never be committed: secrets, virtual environments, large data, and editor caches. A .gitignore file tells Git to skip them.
# Environments
.venv/
node_modules/
# Secrets
.env
# OS / editor noise
.DS_Store
.vscode/
git add .gitignore
git commit -m "Add .gitignore for environments and secrets"
- If you already committed a file by mistake, ask the assistant how to remove it with
git rm --cachedand add it to.gitignore.
Create a new file named .gitignore in the Explorer and paste the rules above. VS Code immediately greys out ignored files and stops listing them under Changes. You can also right-click an unwanted file under Changes and choose Add to .gitignore.
5. Review history and inspect changes
Use these commands to see what happened and to check a change before committing it.
git log --oneline --graph
git diff # unstaged changes
git diff --staged # changes ready to commit
To undo safely without losing work:
git restore --staged <file> # unstage, keep edits
git restore <file> # discard edits in a tracked file (careful)
Ask the assistant to explain a confusing git log or git diff output before you run any command that discards changes.
Click any file under Changes to open a side-by-side diff. Use the Timeline view at the bottom of the Explorer to browse a file's commit history, and right-click a file to Discard Changes (the GUI equivalent of git restore). For a full commit graph, install the Git Graph extension.
6. Push to a remote
A remote is a copy of your repository hosted on a service like GitHub or GitLab. Create an empty repository there (no README), then connect and push.
git remote add origin https://github.com/your-username/git-practice.git
git branch -M main
git push -u origin main
After the first push, later updates are just git push. Your project is now backed up and shareable.
After your first commit, click Publish Branch in the Source Control panel. VS Code prompts you to sign in to GitHub and can create the remote repository for you. After that, use the Sync Changes button (the circular arrows in the status bar) to push and pull.
More prompts to try
- Explain the difference between
git restore,git reset, andgit revert, with a safe example of each. - Look at my last three commits with
git log -p -3and tell me if any commit mixes unrelated changes. - Suggest a
.gitignorefor a Python + Jupyter research project.
Troubleshooting
- If
git commitopens an editor, you left out-m "message". Save and close the editor, or re-run with-m. - If Git says "Author identity unknown", set
user.nameanduser.emailfrom step 1. - If
git pushis rejected, rungit pull --rebasefirst, resolve any conflicts, then push again. - If you committed a secret, treat it as compromised: rotate the credential, then ask the assistant how to remove it from history.
Next steps
- Collaborate on a Project with Git — branches, pull requests, and resolving conflicts with a team.
- Create a Slurm Queue Snapshot CLI — put a small tool you build under version control.