How to Push Your Local Git Repository to a Personal Account and Manage Multiple Configurations

Managing Git repositories can sometimes get tricky, especially when you're switching between accounts (like an organization and a personal account). This guide walks you through the process of pushing your local repository to a remote origin and ensuring the correct account credentials are used.


Step 1: Initialize Git and Push to a Remote Repository

1. Create a Remote Repository

  1. Go to your Git hosting platform (e.g., GitHub, GitLab, Bitbucket).
  2. Create a new repository and copy its URL (e.g., https://github.com/username/repository.git).

2. Link Your Local Repo to the Remote

If you’ve already initiated Git locally, link it to your remote repository using:

git remote add origin <remote-repository-URL>

3. Push Your Code

Push the local code to the remote repository:

git push -u origin main

Replace main with your branch name if it’s different (e.g., master). The -u flag sets the upstream branch for easier future pushes.


Step 2: Changing from an Organization Account to a Personal Account

If your system is still using the credentials of an old organization account while you want to push to your personal account, follow these steps:


Step 2.1: Update Git Configurations

Update your local and global configurations to ensure the correct username and email are used: