Skip to content

Instantly share code, notes, and snippets.

@k4zek4ge
Last active July 25, 2022 08:40
Show Gist options
  • Save k4zek4ge/3b54d0cfe06068f7736e3ae43a87df12 to your computer and use it in GitHub Desktop.
Save k4zek4ge/3b54d0cfe06068f7736e3ae43a87df12 to your computer and use it in GitHub Desktop.
[multiple git accounts] #git
#classic workflow
- create a new 'myapp' repo on github without any commit
- create a folder 'myapp' on local
- drop folder on VScode
- flutter create --org net.apitep .
- git init
- git remote add origin git@github_apitep:mdcdev/myapp.git
- git remote add origin git@sources.corp.medincell.eu:eric.nahon/toolbox_empowerdatatransfer.git
- git remote set-url origin git@github_ericnahon:ericnahon/geography.git
- commit & push from VScode
ls -al ~/.ssh
#
# generate ssh key
#
ssh-keygen -t rsa -C "email@work_mail.com" -f "id_rsa_work_user1"
#
#Adding the new SSH key to the corresponding GitHub account
#
#Copy the public key
pbcopy < ~/.ssh/id_rsa.pub
#and then log in to your personal GitHub account:
1 Go to Settings
2 Select SSH and GPG keys from the menu to the left.
3 Click on New SSH key, provide a suitable title, and paste the key in the box below
4 Click Add key — and you’re done!
#
#Registering the new SSH Keys with the ssh-agent
#
ssh-add ~/.ssh/id_rsa_work_user1
#in case ssh agent is not open
exec ssh-agent bash
#---------------------------------------------------------------------
#Creating the SSH config File
#---------------------------------------------------------------------
cd ~/.ssh/
touch config // Creates the file if not exists
code config // Opens the file in VS code, use any editor
# Personal account, - the default config
Host github.com
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa
# Work account-1
Host github.com-work_user1
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa_work_user1
#----------------------------------------------------------------------
#
#Clone repo
#
git clone git@github.com-work_user1:work_user1/repo_name.git
#
#For Locally Existing Repositories
#If we have the repository already cloned:
#List the Git remote of the repository:
git remote -v
#Check whether the URL matches our GitHub host to be used, or else update the remote origin URL.
git remote set-url origin git@github.com-worker_user1:worker_user1/repo_name.git
git remote set-url origin git@github_mdcdev:mdcdev/mdcusers.git
git remote set-url origin git@github_ericnahon:ericnahon/mdcusers.git
#Ensure the string between @ and : matches the Host we have given in the SSH config.
#
#If you are creating a new repository on local, initialize Git in the project folder:
git init
#Create the new repository in the GitHub account and then add it as the Git remote to the local repository.
git remote add origin git@github.com-work_user1:work_user1/repo_name.git
git remote add origin git@github_mdcdev:mdcdev/mdc_sid_web.git
#Ensure the string between @ and : matches the Host we have given in the SSH config.
#to remove origin
git remote remove origin
#VSCode:
command-shif-p
git@github_k4zek4ge:k4zek4ge/insta.git
git@github_mdcdev:mdcdev/insta.git
#Push the initial commit to the GitHub repository:
git add .
git commit -m "Initial commit"
git push -u origin master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment