因?yàn)镸ac下已經(jīng)自帶了git领虹,所以我們跳過此步驟,如果你是Linux的其他系統(tǒng)求豫,可以使用一下代碼進(jìn)行安裝:
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版本庫
開始一個(gè)新的項(xiàng)目塌衰,初始化新的代碼倉庫,要對(duì)現(xiàn)有的某個(gè)項(xiàng)目開始用 Git 管理蝠嘉,只需到此項(xiàng)目所在的目錄最疆,執(zhí)行:
git init
會(huì)在當(dāng)前目錄下生成一個(gè).git目錄,包含了所有g(shù)it需要的數(shù)據(jù)和資源
進(jìn)行g(shù)it添加蚤告,提交努酸,推送操作
touch README //創(chuàng)建README
git add . //添加左右新增或者改動(dòng)過的文件
git commit -a -m "添加README" //提交變更到本地版本庫
git push origin <branch name> //推送本地版本庫到遠(yuǎn)程倉庫
git克隆遠(yuǎn)程倉庫
//Git本身的源代碼你既可以用 git:// 協(xié)議來訪問:
git clone git@git.jianshu.net:******/****.git
//也可以通過http 協(xié)議來訪問:
git clone https://git.jianshu.net/******/****.git
//自定義目錄名稱,如果不自定義杜恰,默認(rèn)為遠(yuǎn)程倉庫的項(xiàng)目目錄名稱
git clone https://git.jianshu.net/******/****.git mygrit
Git分支操作
查看分支 git branch
創(chuàng)建分支 git branch <branch name>
切換分支 git checkout branch
合并分支 git merge <branch name> //合并某分支到當(dāng)前分支
刪除分支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