- Commands
- Step 1: Check SSH Keys on Your Machine
- Step 2: Generate an SSH Key for Your Business Account
- Step 3: Add the SSH Key to Your Business GitHub Account
- Step 4: Configure the SSH Config File for Multiple Accounts
- Step 5: Test the SSH Configuration
- Step 6: Clone the Repository Using the Business SSH Configuration
- Step 7: Move to the Repository
- Step 8: Confirm Everything Works
- Step 9: Verify the Setup
- Step 10:-Optional-Configure Global Identity and Repository-specific Identity
- GitHub Contribution Graph can be combined by setting the Noreply Email to be the same in both Your Repository or Globally
- (Optional) Use
.gitconfig
Includes for Easier Setup - General clone for Repo
git remote set-url
git remote set-url origin [email protected]:company/your-repo-name.git
- Open your Terminal.
- Run the following command to check if there are any SSH keys already on your Mac:
ls -al ~/.ssh
- Run the following command in Terminal to create a new SSH key:
ssh-keygen -t ed25519 -C "[email protected]"
- When prompted, save the key as:
/Users/amr.elghadban/.ssh/id_ed25519_business_amr_elghadban_adkatech
- Leave the passphrase empty (or add one for security).
- Result:
Your identification has been saved in /Users/amr.elghadban/.ssh/id_ed25519_business_amr_elghadban_adkatech Your public key has been saved in /Users/amr.elghadban/.ssh/id_ed25519_business_amr_elghadban_adkatech.pub The key fingerprint is: SHA256:4AAAAAAhXXXXXXXXXXDyK+M/L2bbbbSs [email protected]
Your identification has been saved in /Users/amr.elghadban/.ssh/id_ed25519_business_amr_elghadban_seddiqiholding Your public key has been saved in /Users/amr.elghadban/.ssh/id_ed25519_business_amr_elghadban_seddiqiholding.pub The key fingerprint is: SHA256:C/ngW1ybCnc7LLGMJDgPobbZ1u26a/60t4762wFgNac [email protected]
- Copy the new public key to your clipboard:
pbcopy < ~/.ssh/id_ed25519_business_amr_elghadban_adkatech.pub
- Go to your GitHub Business account:
- Click your profile picture → Settings.
- Navigate to SSH and GPG keys under Access.
- Click New SSH key.
- Paste the public key into the "Key" field.
- Give it a meaningful title (e.g., MacBook Pro Business Key).
- Click Add SSH key.
- Open the SSH config file:
nano ~/.ssh/config
- If the file doesn't exist, create it:
nano ~/.ssh/config
- Add the following configuration:
# --- Personal GitHub Account --- Host github.aaakk.us.kg-personal HostName github.com User git IdentityFile ~/.ssh/id_ed25519 # UseKeychain yes # AddKeysToAgent yes # ---------------------------- # --- Business GitHub Account --- Host github.aaakk.us.kg-business HostName github.com User git IdentityFile ~/.ssh/id_ed25519_business_amr_elghadban_adkatech # ----------------------------
- Save the file:
- Press
Ctrl + O
, thenEnter
. - Press
Ctrl + X
to exit.
- Press
- Set correct permissions:
chmod 600 ~/.ssh/config
Run the following command to test the SSH connection:
ssh -T [email protected]
Expected Output:
Hi AmrAhmedElghadban! You've successfully authenticated, but GitHub does not provide shell access.
Clone Repositories Using Custom Host Aliases
- (for new clone repo) Use the business SSH alias:
git clone [email protected]:<company>/<reponame>.git
Do not use:
git clone [email protected]:<company>/<reponame>.git
- (for existing clone repo) Navigate to your cloned repository: Open your terminal and go to the root directory of your cloned repository:
cd /path/to/your/repo
Check the current remote URL: Run the following command to see the current remote URL:
git remote -v
This will show something like:
origin [email protected]:<company>/<reponame>.git (fetch)
origin [email protected]:<company>/<reponame>.git (push)
Update the remote URL to use your business SSH alias: Use the git remote set-url command to change the remote URL:
git remote set-url origin [email protected]:<company>/<reponame>.git
Verify the change: Run git remote -v again to confirm the URL has been updated:
git remote -v
You should now see:
origin [email protected]:<company>/<reponame>.git (fetch)
origin [email protected]:<company>/<reponame>.git (push)
Test the connection: To ensure everything is working, you can run:
git fetch
- Decide where to move the repository:
mv ~/POSRetail_Php /Users/amr.elghadban/Desktop/workspace/project_folder
- Verify the move:
You should see the
ls /Users/amr.elghadban/Desktop/workspace/project_folder
project_folder
folder. - Navigate to the new location:
cd /Users/amr.elghadban/Desktop/workspace/project_folder/repo
- Check the Git status:
git status
- Ensure the remote origin is set correctly:
Expected Output:
git remote -v
origin [email protected]:<company>/<reponame>.git (fetch) origin [email protected]:<company>/<reponame>.git (push)
Ensure everything is working as expected.
- Set the identity for global Git identity:
git config --global user.name "Your Personal Name"
git config --global user.email "[email protected]"
- Confirm the settings:
git config --global --list
- Navigate to the repository directory:
cd /Users/amr.elghadban/Desktop/workspace/project_folder/repo
- Set the identity for this repository:
git config user.name "Amr Ahmed Elghadban" git config user.email "[email protected]"
- Check the repository-specific configuration:
git config --list --local
GitHub Contribution Graph can be combined by setting the Noreply Email to be the same in both Your Repository or Globally
git config --global user.email "[email protected]"
git config --global user.name "Amr Angry"
git config user.email "[email protected]"
git config user.name "Amr Elghadban"
If previous commits were made with the wrong email, you can rewrite them with the correct noreply email:
Then, force-push the changes:
git filter-branch --env-filter '
if [ "$GIT_COMMITTER_EMAIL" = "[email protected]" ]; then
export GIT_COMMITTER_EMAIL="[email protected]"
export GIT_AUTHOR_EMAIL="[email protected]"
fi
' -- --all
git push --force
Use .gitconfig
includes to manage multiple identities more efficiently.
#Repo clone from GitHup Stackoverflow
- Create Personal Access Token on GitHub
- Go to this link or From your GitHub account, go to Settings → Developer Settings → Personal Access Token → Tokens (classic) → Generate New Token (Give your password) → click Generate token → Copy the generated Token, it will be something like [ghp_sFhFsSHhTzMDreGRLjmks4Tzuzgthdvfsrta] [(don't go to repository setting; it's your profile setting)]
- Generate a new token and copy-paste it somewhere safely.
- Now search for an app in your Mac, named Keychain Access.
- Search for github.com (if there are multiple GitHub logins then choose Kind: Internet password), double-click it.
- Click on show password, then enter your Mac's password and hit Enter.
- Past the token you generated in step 2 and click Save changes Or
- Set Global config
$ git config --global user.name "your_github_username"
$ git config --global user.email "your_github_email"
$ git config -l
- Now cache the given record in your computer to remembers the token:
$ git config --global credential.helper cache
- If needed, anytime you can delete the cache record by:
$ git config --global --unset credential.helper
$ git config --system --unset credential.helper