How To Use GitHub With Cursor AI
Table of Contents
Introduction
This tutorial guides you through using GitHub with Cursor AI, providing step-by-step instructions on setting up Git, creating repositories, and integrating version control into your development workflow. Whether you're a beginner or refreshing your skills, you'll learn to manage your projects effectively and collaborate seamlessly.
Step 1: Create a GitHub Account
- Visit the GitHub website at github.com.
- Click on the "Sign Up" button.
- Fill in the required details such as username, email, and password.
- Follow the prompts to verify your email address and complete your account setup.
Step 2: Install Git
- Download Git from the official site at git-scm.com.
- Choose the appropriate version for your operating system (Windows, macOS, or Linux).
- Follow the installation instructions based on your platform.
- For Windows, use the installer and select default options.
- For macOS, you can install via Homebrew with the command:
brew install git
Step 3: Configure Git
- Open your command line interface (CLI).
- Set your username and email by entering the following commands:
git config --global user.name "Your Name" git config --global user.email "your.email@example.com"
- Verify your configuration with:
git config --list
Step 4: Initialize a Repository in Cursor AI
- Open Cursor AI and start a new project.
- In the project folder, open the CLI.
- Initialize a new Git repository with:
git init
Step 5: Stage and Commit Changes
- Make changes to your code in Cursor AI.
- Stage the changes with:
git add .
- This command stages all modified files. Adjust the dot to specify individual files if needed.
- Commit the changes with a message:
git commit -m "Your commit message"
Step 6: Publish Your Repository to GitHub
- Create a new repository on GitHub.
- Copy the repository URL.
- Link the local repository to GitHub:
git remote add origin <repository-url>
- Push your changes to GitHub:
git push -u origin master
Step 7: Sync Changes Between Cursor and GitHub
- Whenever you make changes, repeat the staging and committing process.
- To push your updates to GitHub, use:
git push
Step 8: Advanced Git Techniques
-
Discarding Uncommitted Changes: To revert changes in a file:
git checkout -- <file-name>
-
Rolling Back Committed Changes: If you want to undo the last commit:
git reset --soft HEAD~1
-
Forced Push: To overwrite a remote branch:
git push --force
Step 9: Forking and Cloning Repositories
- To fork a repository, go to the GitHub page of the project and click on "Fork."
- Clone your forked repository to your local machine:
git clone <your-fork-url>
Conclusion
You now have the foundational skills to use GitHub with Cursor AI effectively. You've learned how to create and configure a GitHub account, initialize repositories, stage and commit changes, publish your work, and utilize advanced Git features. To further enhance your skills, explore GitHub's collaboration features and consider contributing to open-source projects. Happy coding!