How do I backup my project with git?

百般思念 提交于 2019-12-12 04:46:16

问题


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>

回答1:


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.




回答2:


First of all you need to be have an account.




回答3:


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.



来源:https://stackoverflow.com/questions/44199658/how-do-i-backup-my-project-with-git

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!