How to Add a Git Repository Using the Terminal

Adding a Git repository via the terminal is an essential skill for developers. Whether you’re starting a new project or contributing to an existing one, using Git through the terminal allows you to track changes, collaborate with others, and manage your code efficiently. In this guide, we’ll walk through the simple steps to initialize a repository, link it to a remote, and push your code to GitHub.

To add a Git repository in the terminal, follow these steps:

1. Initialize a Git Repository

Navigate to the directory where you want to initialize the repository and run:

git init

This command initializes a new Git repository in your current directory.

2. Add Remote Repository

To link your local repository with a remote one (e.g., GitHub), use:

git remote add origin https://github.com/username/repository.git

Replace https://github.com/username/repository.git with your actual repository URL.

3. Add Files to Staging Area

Stage the files you want to track with:

git add .

The . stages all changes in the directory. You can also add specific files with:

git add <file_name>

4. Commit Changes

Create a commit with a descriptive message:

git commit -m "Initial commit"

5. Push to Remote Repository

Push your changes to the remote repository:

git push -u origin master

This uploads your code to the main branch (often called master).

Post is part of the XAF Give Camp initiative for students and new developers.

Leave a Reply

Your email address will not be published.