This guide explains how to add code to your GitHub repository using Git Bash for local Git commands and the GitHub web interface for collaboration.
1. Clone the Repository Using Git Bash ๐ฅ๏ธ
Open your repository page on GitHub.
Click the green "Code" button and copy the HTTPS URL.
![git 22]()
Open Git Bash on your computer and run:
git clone <repository-url>
cd <repository-folder>
![Git 2]()
This downloads the full project to your local machine. ๐ป
2. Create a New Branch in Git Bash ๐
Protect the main branch by creating a feature branch:
git checkout -b <branch-name>
Example: git checkout -b version1
![Git 3]()
Work on this new branch to keep changes isolated. ๐
3. Add or Modify Your Code Files โ๏ธ
Create new files or modify existing ones locally:
touch index.html script.js
![Git 4]()
Use your code editor to write or edit code in these files. ๐
![Git 123]()
4. Stage and Commit Your Changes with Git Bash ๐ฆ
Stage all changed files:
git add .
Commit the changes with a descriptive message:
git commit -m "Initial Changes"
![Git 5]()
This records your changes locally. ๐พ
5. Push the Branch to GitHub
Push your branch and changes to the remote repository:
git push origin <branch-name>
Example: git push origin version1
![gut 6]()
This uploads your code safely to GitHub's servers. ๐
6. Open a Pull Request Using GitHub Web
Go to the GitHub repository page in your browser.
You will see a suggestion to open a pull request for the new branch.
![Git 7]()
Click "Compare & pull request."
Add a meaningful title and description of your changes.
![Git 8]()
Click "Create pull request." โจ
![Git 9]()
7. Collaborate, Review, and Merge ๐ค
Collaborate with your team via the pull request.
Once approved, merge the pull request into the main branch.
![Git 10]()
Optionally, delete the feature branch in the GitHub web interface to keep the repository clean. ๐งน
![Git 11]()
| Step | Action | Tool |
|---|
| Clone repo | git clone <url> | Git Bash ๐ฅ๏ธ |
| Create branch | git checkout -b <branch> | Git Bash ๐ |
| Add/Edit code | Write code files locally | Code editor โ๏ธ |
| Stage & commit | git add .+git commit -m | Git Bash ๐ฆ |
| Push branch | git push origin <branch> | Git Bash โ๏ธ |
| Open PR | Use GitHub web to create PR | GitHub Web ๐ |
| Review & merge | Collaborate and merge PR | GitHub Web ๐ค |
![Git 12]()
This workflow combines the power of Git Bash's command-line interface and GitHub's web platform for seamless code addition and collaborative development. ๐
Git Related Articles