1

Please note that I read most of the suggestion o this page, but there are too many suggestions and I cannot find a proper way for my problem.

I created a new repository called demo-project on GitHub and I want to push demo-project that already on my local disk on D:\projects folder. I cloned the repo to D:\projects directory (first I move my project to another location) and then copied my project to that D:\projects folder. Then I connect to GitGub, but it shows lots of changes that I did not make and after pushing the changes to the GitHub, it uses my work account instead of private GitHub.

So;

1. How should I push my changes to the repo on GitHub? Should I first clone that repo and then copy my project to the clone directory (D:\projects)? Or is there an easier way e.g. connecting to repo and then push?

2. How can I use my private GitHub account automatically for this repo when I run commends when I am in this repository (D:\projects\demo-project) on cmd? Should I run the following command for setting my private repo without --global option?

git config user.name "[name]" 
git config user.email "[email]" 
git config user.password "[password]" 
Paul Samsotha
  • 205,037
  • 37
  • 486
  • 720

1 Answers1

0

First you would need to perform this command :

git init

then :

git remote add origin REPO_LINK

REPO_LINK being the link to your repository.

So this command will, "link" your folder to the repository, so when you will commit any changes, it will push the code from the remote (the folder you added the remote to) to the repository.

Edit : It should fix your "Fatal : Not a git repository" error.

unto
  • 16
  • 3
  • I used `git clone REPO_LINK`, but the problem is related to account. Will it set my private Github account for this cloned repo? –  Mar 20 '22 at 20:19
  • You will need to specify the account, use those commands to connect your account to it : $ git config --global user.name "Your name here" $ git config --global user.email "your_email@example.com" – unto Mar 20 '22 at 20:22
  • gives **"fatal: not a git repository (or any of the parent directories): .git"** error when I try to run in either `D:\projects` and `D:\projects\demo-project` –  Mar 20 '22 at 20:22
  • But as I mentioned on my question, if I set my GitHub account globally, does mot it affect my working repo? I use working email for my work projects. Any idea? And could you post it correct steps on your answer? –  Mar 20 '22 at 20:24
  • Chico, it does not change my username. Are you sure that you read my question well? –  Mar 20 '22 at 20:31
  • Changing accounts won't affect your working repo, but you need to make sure that the account you want to push changes from is in the git project either as Developper or Maintainer. – unto Mar 20 '22 at 20:35
  • I just want to push the changes to my private GitHub repo using my private e-mail (or GitHub account). Similarly, push the changes to my Work repo using my work e-mail (my work GitLab account). –  Mar 20 '22 at 20:38
  • Then as I said you will need to set up the account, using the --global option because you can only connect one account, so use those commands before pushing changes : $ git config --global user.name "Your name here" $ git config --global user.email "your_email@example.com" You can't connect more than one account, so whenever you will need to switch account, use those commands – unto Mar 20 '22 at 20:44
  • **1.** Thanks a lot, I think it is good idea to use project specific account and whenever I switch to another project, the previously set up account is getting active. Is that right? –  Mar 20 '22 at 21:10
  • ***2.** And when I set up `user.name`, should I use "Name Surname" or my GitHub name e.g. namesurname of my Github name as namesurname@github.com? –  Mar 20 '22 at 21:11
  • 1. yes that is right! 2.Yep, exactly! You use "Name Surname", so for example I would use : "Matteo D..." – unto Mar 20 '22 at 21:18
  • Thanks a lot Amigo. The last question: I also set password for my GitHub via `git config user.password`. I think if I did not set, it would ask me by opening browser, etc. Is that true? –  Mar 20 '22 at 21:24
  • Yep, normally they should ask you for it! – unto Mar 20 '22 at 21:28