Git使用个人笔记

导入已有工程到Github

  1. 先在github上创建一个repository,为避免其他错误,不生成README等文件。
  2. 配置远程repository的用户名和注册邮箱
    git config --global user.name '<your_github_nick_name>'
    git config --global user.email <your_github_sign_in_email_address>
  3. 切换到项目目录下,比如项目名是test,所以切换到test的根目录下。
  4. 初始化本地目录作为一个Git repository
    $ git init
  5. 新建.gitignore文件设置git提交过滤选项,配置语法:
    * 以斜杠“/”开头表示目录;
    * 以星号“*”通配多个字符;
    * 以问号“?”通配单个字符
    * 以方括号“[]”包含单个字符的匹配列表;
    * 以叹号“!”表示不忽略(跟踪)匹配到的文件或目录;

    此外,git 对于 .ignore 配置文件是按行从上到下进行规则匹配的,意味着如果前面的规则匹配的范围更大,则后面的规则将不会生效;举例说明:

    # ignore special folder
    .git/*
    .vscode/*
    venv/*
    # ignore all folder
    *.pytest_cache/
    # ignore special file
    *.bak
  6. 添加工程修改文件到本地库索引,其中'.'表示
    $ git add .
  7. 提交工程修改文件到本地库
    $ git commit -m "first commit"
  8. 添加远程项目
    (1)找到github上你的项目的url(即:clone url),例如:
    https://github.com/thuanghai/test.git

    (2)提交到远程仓库,'your_nickname'比如为origin

    git remote add <your_nickname> https://github.com/thuanghai/test.git

    注:把本地的repository push到github。其间需要输入github的账号和密码。

猜你喜欢

转载自blog.51cto.com/huanghai/2133157
今日推荐