Git托管:将本地项目代码上传(push)到自己的Git repository

2023-05-16

  1. 首先下载并安装git版本控制软件,我安装的是Git-1.9.2-preview20140411,这里是我上传的有需要的可以download然后安装即可。http://download.csdn.net/detail/u013295579/9793810【下载链接】
    以下命令可以查看自己安装的版本:
$ git --version
git version 1.9.2.msysgit.0

2.步入主题–>>在你需要上传的文件绝对目录下右键,在菜单列表里面打开git bash,在终端里输入:

$ git init
Reinitialized existing Git repository in e:/GITHUBSource/WorkStation/.git/

先来看下终端的git command都有哪些:

$ git
usage: git [--version] [--help] [-C <path>] [-c name=value]
           [--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]
           [-p|--paginate|--no-pager] [--no-replace-objects] [--bare]
           [--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]
           <command> [<args>]

The most commonly used git commands are:
   add        Add file contents to the index
   bisect     Find by binary search the change that introduced a bug
   branch     List, create, or delete branches
   checkout   Checkout a branch or paths to the working tree
   clone      Clone a repository into a new directory
   commit     Record changes to the repository
   diff       Show changes between commits, commit and working tree, etc
   fetch      Download objects and refs from another repository
   grep       Print lines matching a pattern
   init       Create an empty Git repository or reinitialize an existing one
   log        Show commit logs
   merge      Join two or more development histories together
   mv         Move or rename a file, a directory, or a symlink
   pull       Fetch from and integrate with another repository or a local branch
   push       Update remote refs along with associated objects
   rebase     Forward-port local commits to the updated upstream head
   reset      Reset current HEAD to the specified state
   rm         Remove files from the working tree and from the index
   show       Show various types of objects
   status     Show the working tree status
   tag        Create, list, delete or verify a tag object signed with GPG

'git help -a' and 'git help -g' lists available subcommands and some
concept guides. See 'git help <command>' or 'git help <concept>'
to read about a specific subcommand or concept.

看到:init –Create an empty Git repository or reinitialize an existing one.因此我们可以通过它来创建一个空的git托管仓库或者重新初始化已经存在的仓库。

3.use “git add …” to include in what will be committed 即:使用git add命令将文件加入暂存区

$ git add Project #(Project :the file what you want to add.)
warning: LF will be replaced by CRLF in Project/Order_Client/AndroidManifest.xml.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in Project/Order_Client/bin/AndroidManifest.xml.
The file will have its original line endings in your working directory.

可以通过:$ git config core.qutocrlf false 来处理add(将文件加入暂存区)时的警告消息

4.使用git commit命令将当前暂存区中的文件实际保存到仓库历史记录中。通过这些记录,可以在工作树中复原文件。个人觉得这和数据库的日值文件的作用相同,先将操作写入日志,再对数据库操作。

$ git commit -m "this is a Learning Project"
[master (root-commit) 1cadc7e] this is a Learning Project
warning: LF will be replaced by CRLF in Project/Order_Client/AndroidManifest.xml.

git commit -m “First commit” -m参数后的”this is a Learning Project”称作为提交信息,是对这个提交的概述。

5.网页登陆你的github账号,创建仓库这里写图片描述
这里写图片描述
6.copy你的仓库路径
你新建的仓库地址
7.添加远程仓库,在GitHub上创建的仓库路径位”git@gitub.com:用户名/git-tutorial.git”. git remote add 命令可将它设置成本地仓库的远程仓库。

$  git remote add origin https://github.com/******/Project

7.git pull–获取最新的远程仓库分支。

$ git pull origin master
warning: no common commits
remote: Counting objects: 3, done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), done.
From https://github.com/Jacoobr/Project
 * branch            master     -> FETCH_HEAD
 * [new branch]      master     -> origin/master
Merge made by the 'recursive' strategy.
 README.md | 2 ++
 1 file changed, 2 insertions(+)
 create mode 100644 README.md

8.创建同名分支,当工作告一段落时,定期将这个特性分支push到远程仓库。

$ git push -u origin master
Username for 'https://github.com': ***
Password for 'https://***@github.com':
Counting objects: 238, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (218/218), done.
Writing objects: 100% (237/237), 1.12 MiB | 119.00 KiB/s, done.
Total 237 (delta 52), reused 0 (delta 0)
remote: Resolving deltas: 100% (52/52), done.
To https://github.com/***/Project
   88b0e11..0935b3d  master -> master
Branch master set up to track remote branch master from origin.

创建分支过程要输入用户名和用户密码
之后可以登陆git查看下自己提交的代码库
这里写图片描述
bingo!Look,We make it!

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Git托管:将本地项目代码上传(push)到自己的Git repository 的相关文章

随机推荐