0

I want to backup my project, so I have tried initializing a rep with

git init

and then commit all files with

git add .
git commit -am "first commit"

and now I want to push it to a repository (which is not only locally stored).

I know I have to do something like

git push origin master

I know that master is the name of my branch, but what is origin?

Where are the files stored? Do I have to create a repository on GitHub, so the files can be stored on GitHub's servers or are there some Git servers which can store my files for free (I assume not :D)?

So do I have to first create the repository on GitHub and then connect my local project with the GitHub repository with

git remote <url_to_GitHub_rep>
Jamgreen
  • 10,329
  • 29
  • 113
  • 224
  • GitHub *is* free for public/open-source projects. Bitbucket offers free private repositories for individuals and small teams. – Thilo May 26 '17 at 10:51

3 Answers3

4

Create a repository in github and copy the git url(Something Like https://github.com/username/gitname.git ).

Then

git init

git add .

git commit -m "First commit"

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

git remote -v

git push origin master

Then You Will Be Asked Your Github Username & Password.

Now Enter Github Username and Password.

The Files Will Uploaded to your repository.

Thank You.

Adharsh M
  • 2,773
  • 2
  • 20
  • 33
  • 1
    The first time you push use the command use `git push -u origin master` to set the upstream for the repository. For a detailed explanation see this [question](https://stackoverflow.com/questions/37770467/why-do-i-have-to-git-push-set-upstream-origin-branch) – Kronos May 26 '17 at 11:01
  • Yes, Thats Right. – Adharsh M May 26 '17 at 11:26
0

First of all you need to be have an account. enter image description here

enter image description here

siva
  • 315
  • 2
  • 11
  • 2
    Instead of putting screeshots in your answer. Summarise the steps / process in your answer and may be add links and references to the resource. – abhishekkannojia May 26 '17 at 10:56
  • pictures are good, but give little to no metadata required by search engines, so in order for future searchers to find this post, add some related descriptions – Stavm May 26 '17 at 10:58
  • i agree. and will follow the same – siva May 26 '17 at 11:22
0

The most popular way to back up projects with git is using remote git repo.

For the remote git repo, it can be setup on your own server, or it can be hosted on github, bitbucket etc.

The remote repo is the place where you really version control or backup your project. And the local git repo works as working copy for remote repo. You can connect remote repo with local repo with the situations:

Already has local repo (the situation as you have):

git add .
git commit
git remote add origin <remote repo URL>
git push -u origin master

Note:

origin is the default name for the remote repo (similar as master is default branch name), of cause you can use other names to replace origin.

-u (--set-upstream) option is set the tracking relationship between local master branch and remote master branch. You can find your local master is behind or ahead of remote master branch by git status.

Not has local repo:

git clone <remote repo URL>
cd <repo name>
git add .
git commit
git push origin master

Note: when you clone a remote repo locally, git will set the remote name as origin by default.

Community
  • 1
  • 1
Marina Liu
  • 36,876
  • 5
  • 61
  • 74