Setup a Remote Git Repository
Before you can share your work or back it up online, you need a “home” for your project on the internet—this is what we call a remote repository. One of the most popular places to host remote repositories is GitHub (though there are others, like GitLab and Bitbucket). To get started, you first visit the hosting site in your web browser and sign up for an account. Once you’ve created and signed in to your account, you’ll see an option—often a big green button or a “+” icon—to create a new repository. Clicking that will bring you to a form where you give your project a name (for example, “my-first-git-project”) and, optionally, a short description explaining what the project is about.
On this same page you’ll decide whether your repository will be public—visible to anyone on the internet—or private—only accessible to you and people you invite. For students just getting started, a public repository is fine, as it makes it easy to share your work with classmates or ask for feedback. You’ll also have the choice to initialize the repository with a README file, which is a simple text file where you can explain how your project works; it’s a good idea to check this box so that your repository already has one file in it. Finally, click the “Create repository” button at the bottom of the page.
Within seconds, GitHub will set up your new remote repository and present you with clear instructions for connecting it to your local project. These instructions usually include the URL of your remote repository (something like https://github.com/your-username/my-first-git-project.git) and the exact Git commands you’ll run on your computer to finish linking everything together. At this point, you have a brand-new space on the web ready to receive your code, files, and commit history—and you can return here at any time to see a timeline of all the changes you’ve pushed, manage collaborators, or even explore built-in tools for tracking issues and documentation. This remote repository will become the central hub for your project, ensuring that your work is safely stored online and available to anyone you choose to share it with.
The .gitignore File
When you work on a project, there are often files you don’t want Git to track. These might be temporary files your editor creates, large data files that clutter the history, or sensitive information like passwords and API keys. Without a way to tell Git which files to ignore, you could accidentally commit things you don’t intend to share or that simply don’t belong in version control. This is where the .gitignore file comes in.
A .gitignore file lives in the root of your project folder and contains a simple list of patterns—file names, folder names, or file extensions—that tell Git, “Please skip these.” When you run commands like git status or git add ., Git will check your .gitignore file first and automatically exclude any matching items. That means those files will never show up in your list of changes, and you won’t accidentally include them in a commit.
Creating a .gitignore file is as easy as opening your favorite text editor, typing in the names or patterns you want to ignore, and saving the file as .gitignore. For example, if you use a code editor that generates a folder named .vscode for its configuration, you could put a line reading .vscode/ into your .gitignore file. Similarly, if your project uses Python, you might write *.pyc to ignore all compiled byte-code files, or __pycache__/ to skip the entire cache folder. You can also ignore entire folders by simply listing their names, like logs/, or even use wildcard patterns such as temp-*.txt to ignore any file beginning with “temp-” and ending with “.txt.”
It’s important to create your .gitignore file before you start committing, because Git only ignores files that haven’t been tracked yet. If a file is already in your repository history, adding it to .gitignore won’t remove it from previous commits. In that case, you’d need to untrack it manually—usually with a command like git rm --cached filename—so that Git forgets it going forward.
Many communities and programming languages provide sample .gitignore templates that you can copy and adapt. GitHub, for instance, offers a collection of templates for everything from Java and Node.js to Unity and Visual Studio. Starting from a template ensures you cover the most common files you’ll want to ignore, and then you can customize it as your project grows.
By using a well-crafted .gitignore file, you keep your repository clean, protect sensitive or unnecessary files from exposure, and make your version history easier to navigate. It’s a small step that pays off in clearer commits, smaller repository size, and fewer “oops” moments later on.
Understanding Remote Repositories
When you first start working with Git on your own computer, everything you do—creating commits, experimenting on branches, even rolling back to an earlier version—happens in what’s called your local repository. That’s simply the hidden .git folder and all the files in your project directory. A remote repository, by contrast, lives somewhere else—usually on a server out on the internet. Popular hosting services like GitHub, GitLab, or Bitbucket provide these servers so you don’t have to manage the hardware yourself. In Git’s eyes, a remote repository is just another copy of your project’s entire history, one that you can synchronize with whenever you like.
Having a remote repository brings two big benefits right away. First, it acts as a centralized backup of your work. Even if your laptop crashes or your local files get corrupted, you know that every commit you’ve pushed is safely stored on the remote server. You can always clone that remote copy back down and pick up exactly where you left off. Second—and perhaps more importantly for teamwork—a remote repository becomes the common meeting point for everyone contributing to the project. Each person works independently on their own machine and then “pushes” their commits up to the remote. Likewise, they “pull” in changes that others have pushed. This workflow makes it possible for multiple students to develop code simultaneously without overwriting each other’s work, and it keeps a clear, shared history of who did what and when.
Throughout this article, we’ll use the name origin as the conventional label for the primary remote repository you connect to. You’ll learn the exact commands in the next section to link your local project to origin on GitHub. Once connected, pushing and pulling become simple one-line Git commands that keep your local and remote repositories in sync. With this foundation in place, you’ll enjoy the safety of off-site backups and the freedom to collaborate smoothly with classmates on any coding assignment or group project.
Connecting Your Local Repository to GitHub
Once you have a folder on your computer ready for version control, the first step toward sharing it online is to turn it into a Git repository. Open your terminal (or command prompt) and navigate into your project’s folder. There, typing git init will create a hidden .git directory, which is where Git stores all of its tracking information. At this point, your project is now a local Git repository—but it still lives only on your own machine.
With your local repository initialized, you’ll want to record your first snapshot of the project. You do this by staging and committing your files: run git add . to tell Git to prepare all of your current files for a commit, then type git commit -m "Initial commit" to capture that snapshot in your history. The message inside the quotes is a brief description of what this commit contains; since it’s your very first commit, calling it “Initial commit” has become a friendly convention.
Next comes the connection to GitHub. When you created your remote repository on the GitHub website, it gave you a URL that looks something like https://github.com/your-username/my-first-git-project.git. You tell your local repository about this remote location by running git remote add origin <that-URL>. The word “origin” is simply a nickname that Git uses to remember which remote repository you’ll be working with most of the time. From now on, when you push or pull changes without specifying a remote, Git assumes you mean “origin.”
Finally, sharing your work is as simple as pushing your commits up to GitHub. By running git push -u origin main (or, in older tutorials, git push -u origin master), you send your local “main” branch and all its commits to the remote repository named “origin.” The -u flag sets up a tracking relationship so that future pushes and pulls can be done by typing just git push or git pull without naming the branch or remote. A few moments later, if you refresh your repository page on GitHub, you’ll see the files you committed—and you’ll know your work is safely stored online and ready for collaboration.
Last updated