I have to accounts of github. One of them has a repository. But I want to add file…
- User
I have to accounts of github. One of them has a repository. But I want 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 to a GitHub repository from a different account (like collaborating with a team member), you have a few options. Here’s a step-by-step guide on how you can add a file (
persistent.h) to a repository owned by the first account while using your second account.Option 1: Collaborator Access
-
Request Access: If you have a GitHub account with a different email address, you can ask the owner of the repository (your first account) to add your second account as a collaborator.
-
Add Collaborator:
- The owner should go to the repository on GitHub.
- Go to Settings > Collaborators & teams.
- Add your second GitHub account as a collaborator by typing in the username or email and clicking Add.
-
Clone the Repository:
- Open a terminal or Git Bash.
- Clone the repository with the following command:
git clone https://github.com/first-account/repository-name.git - Replace
first-accountwith the owner account name andrepository-namewith the name of the repository.
-
Switch to the Repository Directory:
cd repository-name -
Add the File:
- Use a text editor or command line to create
persistent.h:touch persistent.h
- Use a text editor or command line to create
-
Stage and Commit:
git add persistent.h git commit -m "Add persistent.h" -
Push Changes:
git push origin main- Make sure to replace
mainwith the appropriate branch name if it's different.
- Make sure to replace
Option 2: Fork the Repository
If you cannot get collaborator access, you can fork the repository and create a pull request.
-
Fork the Repository:
- Log into your second GitHub account.
- Navigate to the repository owned by the first account.
- Click on the “Fork” button to create a copy of the repository in your second account.
-
Clone Your Fork:
git clone https://github.com/your-second-account/repository-name.git cd repository-name -
Add the File:
- Create
persistent.husing a text editor or command line:touch persistent.h
- Create
-
Stage and Commit:
git add persistent.h git commit -m "Add persistent.h" -
Push Changes:
git push origin main -
Create a Pull Request:
- Go to your forked repository on GitHub.
- You’ll see a banner suggesting to create a pull request. Click on it.
- Provide a title and description.
- Submit the pull request.
-
Merge Pull Request:
- The owner of the original repository can then review and merge your pull request.
Option 3: Direct Upload
If you want to directly upload the file without cloning the repository:
-
Log into Your First GitHub Account: Ensure you're logged into the second account that has collaborator access.
-
Navigate to the Repository: Go to the repository where you want to add the file.
-
Upload the File:
- Click on Add file > Upload files.
- Drag and drop
persistent.hor use the file selector. - Scroll down and click Commit changes.
By following any of these methods, you should be able to add the file to the GitHub repository from your second account.
-