There are two accounts of github. One of them has a repository. How to add file ("persistant.h") to this repository from the second account? It's like a team job. How can I make it?
Assistant
To add a file like "persistent.h" from a second GitHub account to a repository owned by another account (Team job scenario), you typically follow these steps:
1. Collaborate through GitHub
If you want to contribute to a repository from another account, the best way is to collaborate by following the standard GitHub workflow using forks and pull requests:
Step A: Fork the Repository
Log into the second GitHub account (the one without the repository).
Find the repository you want to contribute to (owned by the first account).
Click on the "Fork" button in the upper right corner of the repository page. This creates a copy of the repository in your own account.
Step B: Clone the Forked Repository
After forking, you’ll be taken to your forked repository (located in your second account).
Click the "Code" button and copy the URL of your fork.
Open the terminal or Git Bash on your computer.
Run the following command to clone your forked repository:
bash
git clone <URL-of-your-forked-repo>
Replace <URL-of-your-forked-repo> with the actual URL you copied.
Step C: Add the File
Navigate to the forked repository's folder on your local machine:
bash
cd <name-of-your-forked-repo>
Create the "persistent.h" file (you can do this via any text editor):
bash
touch persistent.h
Add content to "persistent.h" as needed.
Add the file to your local Git repository:
bash
git add persistent.h
Commit your changes:
bash
git commit -m "Add persistent.h file"
Step D: Push to Your Fork on GitHub
Push your changes to your forked repository on GitHub:
bash
git push origin main
Modify main with your current branch name if it’s different.
Step E: Create a Pull Request
Go back to your forked repository on GitHub.
You should see a prompt to create a pull request for your new changes. Click on "Compare & pull request".
Provide a title and a description for your pull request explaining what you've done.
Click "Create pull request".
2. Ask for Collaborator Access
Alternatively, if you are collaborating closely, you can ask the owner of the original repository (the first account) to add your second GitHub account as a collaborator on that repository.
The repository owner can go to their repository settings.
Under the "Manage access" tab, they can invite you (your second account's GitHub username) as a collaborator.
Once you accept the invitation, you can clone the original repository, make changes directly, and push those changes back.
Summary
Using the forking and pull request method is a common practice in open source projects and team collaborations on GitHub. It allows for code review and discussions before merging changes into the main repository.
If you’re part of a team and working with private repositories, collaborating through direct access by adding collaborators can streamline the process once permissions are granted.