Using Git Bash: Clone, Modify, and Push Code to a Repository

2025. 4. 25. 01:53Embedded Development

Sure! Here's a detailed document in English explaining how to use Git Bash to clone a repository into a new folder, make code modifications, and push the changes back to the repository:


📘 Using Git Bash: Clone, Modify, and Push Code to a Repository

This guide explains how to clone a Git repository into a new folder, modify the code, and push the changes back using Git Bash.


🔧 Prerequisites

Before starting, ensure that:

  • Git is installed on your system: https://git-scm.com/downloads
  • You have access to the repository (with proper credentials or SSH keys if private)
  • Git Bash is available (installed with Git on Windows)

1. 🔽 Clone the Repository into a New Folder

  1. Open Git Bash.

  2. Navigate to the location where you want to create the new folder:

    cd /c/Users/YourUsername/Documents/
  3. Clone the repository into a new folder:

    git clone https://github.com/username/repository-name.git new-folder-name

    Example:

    git clone https://github.com/johnsmith/my-app.git my-app-new
  4. Enter the cloned directory:

    cd my-app-new

2. 🛠 Modify the Code

You can now open the files inside the folder using a code editor (e.g., VS Code, Notepad++, etc.), and make your desired changes.

Example (with VS Code):

code .

3. ✅ Stage the Changes

Once the modifications are done, go back to Git Bash and check what has been changed:

git status

Then, add the modified files to the staging area:

git add .

Or specify specific files:

git add path/to/file1 path/to/file2

4. 💬 Commit the Changes

Commit your changes with a clear message:

git commit -m "Fix: Updated user input validation logic"

5. ⬆ Push the Changes to the Remote Repository

If you're on the main branch:

git push origin main

If you're on a feature branch (recommended for new work):

git push origin feature-branch-name

6. 🧠 Optional: Create a New Branch (Recommended for Feature Work)

Before starting changes, you can create and switch to a new branch:

git checkout -b feature/my-new-feature

After editing and committing:

git push origin feature/my-new-feature

✅ Summary

Step Command
Clone git clone <repo-url> <new-folder>
Check changes git status
Stage changes git add .
Commit changes git commit -m "your message"
Push to remote git push origin <branch-name>