Mac 下 Git 的基础命令行操作

因为Mac下已经自带了git,所以我们跳过此步骤,如果你是Linux的其他系统,可以使用一下代码进行安装:

sudo apt-get install git-core //安装Git

用户配置

git config --global user.name "Your Name" //配置用户名称
git config --global user.email "Your Email" //配置用户邮箱
git config --list //查看配置信息

第一次初始化git版本库
开始一个新的项目,初始化新的代码仓库,要对现有的某个项目开始用 Git 管理,只需到此项目所在的目录,执行:

git init

会在当前目录下生成一个.git目录,包含了所有git需要的数据和资源
进行git添加,提交,推送操作

touch README //创建README
git add . //添加左右新增或者改动过的文件
git commit -a -m "添加README" //提交变更到本地版本库
git push origin <branch name> //推送本地版本库到远程仓库

git克隆远程仓库

//Git本身的源代码你既可以用 git:// 协议来访问:
git clone git@git.jianshu.net:******/****.git
//也可以通过http 协议来访问:
git clone https://git.jianshu.net/******/****.git
//自定义目录名称,如果不自定义,默认为远程仓库的项目目录名称
git clone https://git.jianshu.net/******/****.git mygrit

Git分支操作

查看分支 git branch
创建分支 git branch <branch name>
切换分支 git checkout branch
合并分支 git merge <branch name> //合并某分支到当前分支
删除分支git branch -d <branch name>

mac git --help
These are common Git commands used in various situations:
start a working area (see also: git help tutorial)

clone Clone a repository into a new directory
init Create an empty Git repository or reinitialize an existing one

work on the current change (see also: git help everyday)

add Add file contents to the index
mv Move or rename a file, a directory, or a symlink
reset Reset current HEAD to the specified state
rm Remove files from the working tree and from the index

examine the history and state (see also: git help revisions)

bisect Use binary search to find the commit that introduced a bug
grep Print lines matching a pattern
log Show commit logs
show Show various types of objects
status Show the working tree status

grow, mark and tweak your common history

branch List, create, or delete branches
checkout Switch branches or restore working tree files
commit Record changes to the repository
diff Show changes between commits, commit and working tree, etc
merge Join two or more development histories together
rebase Reapply commits on top of another base tip
tag Create, list, delete or verify a tag object signed with GPG

collaborate (see also: git help workflows)

fetch Download objects and refs from another repository
pull Fetch from and integrate with another repository or a local branch
push Update remote refs along with associated objects

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 因为原文太长超出字数,Lesson 3 就放在另一篇文章里 How to Use Git and GitHub 标...
    赤乐君阅读 10,687评论 1 5
  • origin websiteComparing WorkflowsCentralized Workflow Fea...
    伍帆阅读 3,452评论 0 0
  • 股指在经历了昨天的大幅下跌之后,今天两市包括创业板都收红了,其中深市和中小板、创业板表现要强于沪市,盘中反弹的主要...
    天天随缘风起阅读 1,027评论 0 0
  • 现在是半夜11:53分,我坐在出租屋的床上,泡着脚。 昨天晚上本来想写点东西的,电脑都打开了,点击了浏览器,连“简...
    青木729阅读 2,600评论 2 1
  • 在归学校途中,在同和处难得挤了一班上班高峰期的地铁,我好像懂得了什么叫做人生险恶。 不要说一席之地,有双脚之地就谢...
    奶牛软木阅读 3,663评论 0 2