git学习(一)

一、在GitHub上新建一个代码仓库,如gitteach01

二、本地安装git

三、创建本地git仓库

tangxuefengdeMacBook-Pro:~ tangxuefeng$ mkdir gitteach01
tangxuefengdeMacBook-Pro:~ tangxuefeng$ cd gitteach01/
tangxuefengdeMacBook-Pro:gitteach01 tangxuefeng$ echo 1 > 1.txt
tangxuefengdeMacBook-Pro:gitteach01 tangxuefeng$ echo 2 > 2.txt
tangxuefengdeMacBook-Pro:gitteach01 tangxuefeng$ git init
Initialized empty Git repository in /Users/tangxuefeng/gitteach01/.git/
tangxuefengdeMacBook-Pro:gitteach01 tangxuefeng$ git status
On branch master

No commits yet

Untracked files:
  (use "git add <file>..." to include in what will be committed)

	1.txt
	2.txt

nothing added to commit but untracked files present (use "git add" to track)
tangxuefengdeMacBook-Pro:gitteach01 tangxuefeng$ git add 1.txt
tangxuefengdeMacBook-Pro:gitteach01 tangxuefeng$ git status
On branch master

No commits yet

Changes to be committed:
  (use "git rm --cached <file>..." to unstage)

	new file:   1.txt

Untracked files:
  (use "git add <file>..." to include in what will be committed)

	2.txt

tangxuefengdeMacBook-Pro:gitteach01 tangxuefeng$ git add 2.txt
tangxuefengdeMacBook-Pro:gitteach01 tangxuefeng$ git status
On branch master

No commits yet

Changes to be committed:
  (use "git rm --cached <file>..." to unstage)

	new file:   1.txt
	new file:   2.txt

tangxuefengdeMacBook-Pro:gitteach01 tangxuefeng$ mkdir dir1
tangxuefengdeMacBook-Pro:gitteach01 tangxuefeng$ git status
On branch master

No commits yet

Changes to be committed:
  (use "git rm --cached <file>..." to unstage)

	new file:   1.txt
	new file:   2.txt

tangxuefengdeMacBook-Pro:gitteach01 tangxuefeng$ echo 3 > dir1/3.txt
tangxuefengdeMacBook-Pro:gitteach01 tangxuefeng$ git status
On branch master

No commits yet

Changes to be committed:
  (use "git rm --cached <file>..." to unstage)

	new file:   1.txt
	new file:   2.txt

Untracked files:
  (use "git add <file>..." to include in what will be committed)

	dir1/

tangxuefengdeMacBook-Pro:gitteach01 tangxuefeng$ git add dir1/
tangxuefengdeMacBook-Pro:gitteach01 tangxuefeng$ git status
On branch master

No commits yet

Changes to be committed:
  (use "git rm --cached <file>..." to unstage)

	new file:   1.txt
	new file:   2.txt
	new file:   dir1/3.txt

tangxuefengdeMacBook-Pro:gitteach01 tangxuefeng$ echo 4 > dir1/4.txt
tangxuefengdeMacBook-Pro:gitteach01 tangxuefeng$ git status
On branch master

No commits yet

Changes to be committed:
  (use "git rm --cached <file>..." to unstage)

	new file:   1.txt
	new file:   2.txt
	new file:   dir1/3.txt

Untracked files:
  (use "git add <file>..." to include in what will be committed)

	dir1/4.txt

tangxuefengdeMacBook-Pro:gitteach01 tangxuefeng$ git add dir1/4.txt
tangxuefengdeMacBook-Pro:gitteach01 tangxuefeng$ git status
On branch master

No commits yet

Changes to be committed:
  (use "git rm --cached <file>..." to unstage)

	new file:   1.txt
	new file:   2.txt
	new file:   dir1/3.txt
	new file:   dir1/4.txt

tangxuefengdeMacBook-Pro:gitteach01 tangxuefeng$ git commit -m "add files and dir"
[master (root-commit) c5502d7] add files and dir
 4 files changed, 4 insertions(+)
 create mode 100644 1.txt
 create mode 100644 2.txt
 create mode 100644 dir1/3.txt
 create mode 100644 dir1/4.txt

四、推送代码到GitHub

tangxuefengdeMacBook-Pro:gitteach01 tangxuefeng$ git remote add origin https://github.com/StevenTangBUPT/gitteach01.git
tangxuefengdeMacBook-Pro:gitteach01 tangxuefeng$ git push -u origin master
Counting objects: 7, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (7/7), 371 bytes | 371.00 KiB/s, done.
Total 7 (delta 0), reused 0 (delta 0)
remote: 
remote: Create a pull request for 'master' on GitHub by visiting:
remote:      https://github.com/StevenTangBUPT/gitteach01/pull/new/master
remote: 
To https://github.com/StevenTangBUPT/gitteach01.git
 * [new branch]      master -> master
Branch 'master' set up to track remote branch 'master' from 'origin'.

说明:

[x]运行 git remote add <shortname> <url> 

添加一个新的远程 Git 仓库,同时指定一个你可以轻松引用的简写:

$ git remote

origin

$ git remote add pb https://github.com/paulboone/ticgit

$ git remote -v

origin  https://github.com/schacon/ticgit (fetch)

origin  https://github.com/schacon/ticgit (push)

pb      https://github.com/paulboone/ticgit (fetch)

pb      https://github.com/paulboone/ticgit (push)

[x]推送到远程仓库

当你想分享你的项目时,必须将其推送到上游。 这个命令很简单:git push [remote-name] [branch-name]。 当你想要将 master 分支推送到 origin 服务器时(再次说明,克隆时通常会自动帮你设置好那两个名字),那么运行这个命令就可以将你所做的备份到服务器:

$ git push origin master

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

猿二小

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值