DEV Community

Cover image for How to Manage Git Remotes and Add Files โ€“ Beginner Friendly Tutorial
Anusha Kuppili
Anusha Kuppili

Posted on

How to Manage Git Remotes and Add Files โ€“ Beginner Friendly Tutorial

Hey everyone! ๐Ÿ‘‹

Today, I'm going to walk you through a simple and beginner-friendly Git tutorial. We will learn how to add a new remote to your Git repository, add and commit a new file, and finally push your changes to the remote repository.

This tutorial assumes you have a local Git repository and you want to update your remotes and add a file from your server. Don't worry if you're new to Git โ€” I'll explain everything step-by-step!


Why do you need to manage remotes?

A remote in Git is like a bookshelf where you keep your projectโ€™s copies, usually on another server or online service like GitHub.

Sometimes, your team adds new remotes that you need to connect to so you can push or pull changes from different places.


Step 1: Adding a New Remote to Your Local Repository

First, open your terminal and navigate to your project folder. For example:

cd /usr/src/kodekloudrepos/blog
Enter fullscreen mode Exit fullscreen mode

Once inside your project folder, add a new remote by running:

git remote add dev_blog /opt/xfusioncorp_blog.git
Enter fullscreen mode Exit fullscreen mode

Here, dev_blog is the name of your new remote, and /opt/xfusioncorp_blog.git is the path to the new remote repository.


Step 2: Adding a New File from Your Server and Committing It

Now, there might be a file on your server, say /tmp/index.html, that you want to include in your project.

Copy it into your working directory:

cp /tmp/index.html .
Enter fullscreen mode Exit fullscreen mode

Next, tell Git to prepare this file for commit by staging it:

git add index.html
Enter fullscreen mode Exit fullscreen mode

Finally, commit the change with a clear message:

git commit -m "Add index.html from /tmp/index.html"
Enter fullscreen mode Exit fullscreen mode

Step 3: Push Your Changes to the New Remote

Now, youโ€™re ready to push your changes to the new remote you added earlier.

Run the following command:

git push dev_blog master
Enter fullscreen mode Exit fullscreen mode

This command uploads your master branch changes to the dev_blog remote.


Summary of Commands

To wrap it all up, here are the commands youโ€™ll use:

cd /usr/src/kodekloudrepos/blog
git remote add dev_blog /opt/xfusioncorp_blog.git
cp /tmp/index.html .
git add index.html
git commit -m "Add index.html from /tmp/index.html"
git push dev_blog master
Enter fullscreen mode Exit fullscreen mode

Final Thoughts

Git might seem intimidating at first, but managing remotes and pushing changes becomes easier with practice.

If youโ€™re just starting out, try these commands on a sample project to get comfortable.

Thanks for reading! If you found this helpful, feel free to share or comment below.

Happy coding! ๐Ÿš€


If you'd like video tutorials related to this topic, check out my Git tutorials on YouTube.

Top comments (0)