4

I am new to GIT.

I have used git init to create a new GIT repo locally. I have practiced with add/commit. Now I want to try using git pull/push and for this I need a remote repository.

I can create a repo on github and clone it on my local machine. Instead, I want to use the existing local repo from my PC and push it somewhere. I guess to github? What is the way to do this?

emremrah
  • 1,733
  • 13
  • 19
variable
  • 8,262
  • 9
  • 95
  • 215
  • If you just want to experiment, you could just clone your repo locally. `git clone path/to/original/repo`. Now you can go to the newly cloned repo and experiment with pulling/pushing to your original repo. – Alderath Jan 08 '20 at 11:40
  • No. I have a repo on my PC. I want to put this on remote. – variable Jan 08 '20 at 11:50
  • 1
    GitHub will have readily available documentation on how to do this. It should be available on a newly created repo, without even having to go looking for it ;-) – underscore_d Jan 08 '20 at 12:05

2 Answers2

0

You can use the command git remote to do this.

Just add a remote repo to your local repo with:

git remote add origin https://github.com/username/yourRepository.git

Then you can do your first push. With simple command git push.

After that you can do all remote operation like fetch,pull and push.

Zig Razor
  • 3,381
  • 2
  • 15
  • 35
0

If you just want to train your push/pull skills you can definitely create a GitHub project and then use that.

The way to do it is to go to your GH account, go to new repository, then when you create it you'll have this screen infront of you.

enter image description here

You can see that there is a section for ...or push an existing repository from the command line. Execute the two commands you see there in your local repository and then you'll be ready to go!

But wait, there is more. You don't even have to use GitHub to have a remote! You can have your very own remote locally!

You can create a local directory, let's call it local-git-repo.git

mkdir local-git-repo.git

Then in it we can execute

git init --bare

Then in your actual projcet you can do the following

git add remote origin <path to your git repo>

and done! You have your own local repo which you can maintain!

mnestorov
  • 4,116
  • 2
  • 14
  • 24
  • This is a duplicate questions, and I would like to delete it. For this, please can you delete your answer. – variable Jan 08 '20 at 12:54
  • 2
    @variable Why do you want to delete the question instead of leaving it up for others? It might help other people. This question, and its answers, are not *just for you*, they are for everyone who might have the same situation. –  Jan 08 '20 at 18:05