Tuesday, February 23, 2021

push an existing repository from the local computer to git repo using command line

 Create a github account with username and password .

When you want to make a folder as git repository, associate that repository with the corresponding github account by adding the same username and password.

 

 To push an existing repository

 

Go to var/www/html/project-folder


git init

git config --global user.name "Your Name"

git config --global user.email "Your Email"

--------------------------------------------------------

git config --list to check current username & email

  1. Change username & email as desired. Make it a global change or specific to the local repo:
    git config [--global] user.name "Full Name"
    git config [--global] user.email "email@address.com"
  2. Per repo basis you could also edit .git/config manually instead
  3. -------------------------------------------------------------------------------------------------------------

 

create github repository

Add local machine ssh key to your github settings ssh


git remote add origin git@github.com:username/github_repo_name.git
git add . //to add all files
git commit -am “adding new project” //t
git push origin master

Please make sure you have the correct access rights
----------------------------------------------------
in case of any errors remove the remote origin,  then reset it in the following way:
-----------------------------------------------------------------------------------
 git remote rm origin
 git remote add origin https://github.com/AIU-Repo/AWSlabLaravel.git
 git remote set-url origin https://github.com/AIU-Repo/AWSlabLaravel.git
 git rm README.md

git pull origin master --allow-unrelated-histories

        git remote add origin  https://USERNAME:PASSWORD@github.com/username/reponame.git 
or       git remote add origin git@github.com:username/reponame.git  
 References:
https://www.atlassian.com/git/tutorials/syncing/git-pull 
--------------------------------------------------------------------------------

Setup local repo as git and push to GitHub

-Create a repo in the GitHub
-Create Laravel project in the local
$cd to that project
$git init

git config --global user.name "Your Name"

git config --global user.email "Your Email"
git remote add origin https://github.com/infra-admin1/LAB_MNGMNT_LARAVEL.git

git remote set-url origin https://github.com/infra-admin1/LAB_MNGMNT_LARAVEL.git
git config --global user.name "infra-admin1"
git config --global user.email "license.admin@aiu.edu.kw"

Create a branch master from current state in the local
You're in a detached state (HEAD detached from v12.0.11). Create a new branch from it:
git checkout -b master 

🔹 Step 2: Push to GitHub
 You want to overwrite GitHub with your local project (force push)

git branch -m master
git push origin master --force

No comments:

Post a Comment