新建项目添加到git上步骤

    xiaoxiao2022-06-24  42

    1、在Git网站上创建项目git库

    2、本地创建项目文件

    3、命令行:切换到本地项目文件夹下

    cd MySecondDemo/

    4、命令行:初始化git

    yuanzhiying:MySecondDemo yuanzhiying$ git init

    Initialized empty Git repository in /Users/yuanzhiying/Code/MySecondDemo/.git/

    5、命令行:

    yuanzhiying:MySecondDemo yuanzhiying$ git add .

    6、命令行:

    yuanzhiying:MySecondDemo yuanzhiying$ git commit -m "first commit"

    7、命令行:

    yuanzhiying:MySecondDemo yuanzhiying$ git remote add origin git@git.oschina.net:yuanzhiying/MySecondDemo.git

    8、命令行:

    yuanzhiying:MySecondDemo yuanzhiying$ git push origin master

    结果出错:

    To git@git.oschina.net:yuanzhiying/MySecondDemo.git

     ! [rejected]        master -> master (fetch first)

    error: failed to push some refs to 'git@git.oschina.net:yuanzhiying/MySecondDemo.git'

    hint: Updates were rejected because the remote contains work that you do

    hint: not have locally. This is usually caused by another repository pushing

    hint: to the same ref. You may want to first integrate the remote changes

    hint: (e.g., 'git pull ...') before pushing again.

    hint: See the 'Note about fast-forwards' in 'git push --help' for details.

    9、命令行:

    yuanzhiying:MySecondDemo yuanzhiying$ git pull origin master

    结果:

    warning: no common commits

    remote: Counting objects: 5, done.

    remote: Compressing objects: 100% (4/4), done.

    remote: Total 5 (delta 0), reused 0 (delta 0)

    Unpacking objects: 100% (5/5), done.

    From git.oschina.net:yuanzhiying/MySecondDemo

     * branch            master     -> FETCH_HEAD

     * [new branch]      master     -> origin/master

    Merge made by the 'recursive' strategy.

     .gitignore |  20 ++++

     LICENSE    | 339 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

     README.md  |   1 +

     3 files changed, 360 insertions(+)

     create mode 100644 .gitignore

     create mode 100644 LICENSE

     create mode 100644 README.md

    10、命令行

    yuanzhiying:MySecondDemo yuanzhiying$ git push origin master

    结果:

    Counting objects: 29, done.

    Delta compression using up to 4 threads.

    Compressing objects: 100% (26/26), done.

    Writing objects: 100% (29/29), 13.43 KiB | 0 bytes/s, done.

    Total 29 (delta 2), reused 0 (delta 0)

    To git@git.oschina.net:yuanzhiying/MySecondDemo.git

       ef139dd..d34ead5  master -> master

    11、命令行

    yuanzhiying:MySecondDemo yuanzhiying$ git pull

    There is no tracking information for the current branch.

    Please specify which branch you want to merge with.

    See git-pull(1) for details

        git pull <remote> <branch>

    If you wish to set tracking information for this branch you can do so with:

        git branch --set-upstream-to=origin/<branch> master

    12、命令行:

    yuanzhiying:MySecondDemo yuanzhiying$ git branch -a

    master

      remotes/origin/master

    13、命令行

    yuanzhiying:MySecondDemo yuanzhiying$ git branch --set-upstream-to=origin/master master

    Branch master set up to track remote branch master from origin.

    这样在我们每次想push或者pull的时候,只需要 输入git push 或者git pull即可

    转载请注明原文地址: https://ju.6miu.com/read-1123721.html

    最新回复(0)