【问题标题】:GIT SSH Connection to server and create repository there and add filesGIT SSH 连接到服务器并在那里创建存储库并添加文件
【发布时间】:2024-05-04 04:55:02
【问题描述】:

我需要 git 方面的帮助。 我有一个服务器、用户名和 parol。我成功连接了 ssh,但我无法添加文件。当我想使用 git add 使用 bash 添加文件(从我的本地电脑)时,它返回找不到文件路径或路径不存在。我认为它正在搜索服务器中的文件或目录。

谢谢。

【问题讨论】:

    标签: windows git ssh version


    【解决方案1】:

    使用 Git,您无需直接在服务器上创建存储库。相反,你

    • 在本地创建存储库 (git init),
    • 向其中添加文件,通常包括两个步骤:
      • 暂存文件 (git add)
      • 将暂存文件提交到本地存储库 (git commit)
    • 为其分配远程服务器的存储库 (git remote add)
      • 注意 1:我假设您已经以某种方式创建了一个远程存储库 - 请参阅您的服务器说明。
      • 注意 2:您在服务器上创建了一个空存储库。
    • 将您的本地存储库上传到远程存储库 (git push)

    示例脚本:

    $ cd your_local_project_dir/              # Get into your your project directory
    
    $ git init                                # Initialize a local repository
    
    $ git add --all                           # Stage all files from your local project
                                              # directory for commit (note this is not
                                              # adding to the repository yet, it's just
                                              # "prepare them to add into the repo")
    
    $ git commit -m "Initial commit"          # Add the staged files to the local repository
    
    $ git remote add origin https://server.com/user/project_name.git
                                              # Link the local repository to a remote one
    
    $ git push -u origin master               # Upload you local repository data to the
                                              # remote one
    

    【讨论】:

    • 感谢您的回答。我已经完成了,直到添加原点。我不知道我怎么能做到这一点。我只有 ip 地址服务器和用户名 - 用于 ssh 连接的 parol。
    • @SamirAgcayev,您需要在该服务器上创建一个空存储库。是公共服务器吗?
    • 然后您必须与该服务器建立 SSH 会话并从 this post 运行三个命令。显然,你必须使用你的路径。