How to Fork a Repository
To fork a repository means to create a personal copy where you can make changes independently of the original codebase. If you find a project you'd like to contribute to, start by forking it so you can have your own version to update as needed.
Example Scenario:
You want to fork codedepot/original-repo
and create a new repository contrib/destination-repo
to hold your changes.
Prerequisites:
Ensure that the destination repository (contrib/destination-repo) is created on your Git before you start the forking process.
Steps to Fork a Repository
1. Set URL variables:
Set the URLs for the original and destination repositories.
export ORIGINAL_REPOSITORY_URL=git@codedepot.ai/codedepot/original-repo.git
export DESTINATION_REPOSITORY_URL=git@codedepot.ai/contrib/destination-repo.git
2. Clone the original repository:
Clone the repository you want to fork using the URL of the original repository.
git clone $ORIGINAL_REPOSITORY_URL destination-repo
3. Change directories to the location of the fork you cloned:
cd destination-repo
4. Rename the original remote:
This step changes the remote name from origin to upstream. This is useful for keeping track of the original repository.
git remote rename origin upstream
5. Add your fork (destination repository) as a new remote:
Add your destination repository as the new origin.
git remote add origin $DESTINATION_REPOSITORY_URL
6. Push changes to your fork (destination repository):
This effectively copies all content from the original to your destination repository.
git push -u origin main