GitHub 教程

安装git

brew install git

安装完成后,终端输入git 出现以下使用提示

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

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

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

选择一个合适的地方,创建一个空目录,作为你的版本库,并进入

mkdir git_project
cd git_project/

将此版本库作为git可以追踪的版本仓库

git init

此时可以看到当前目录增加了.git文件

ls -al
total 0
drwxr-xr-x  3 user  staff   96  3 20 17:32 .
drwxr-xr-x  9 user  staff  288  3 20 17:32 ..
drwxr-xr-x  9 user  staff  288  3 20 17:32 .git

创建分支

(py_3) $ git checkout -b user  #创建并且换到新分支
Switched to a new branch 'user'

(py_3) $ git branch   #查看当前所处分支
  master
* user

此时你的git仓库就创建好了,该目录下的任何一个文件的修改都将进入Git的追踪, 将任意项目代码移到该仓库下

git status
On branch master

No commits yet

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

    .DS_Store
    my_web/

nothing added to commit but untracked files present (use "git add" to track)

经过修改代码后,使用git diff 查看修改痕迹

(py_3) $ git diff
diff --git a/my_web/manage.py b/my_web/manage.py
index e2df482..de6440e 100755
--- a/my_web/manage.py
+++ b/my_web/manage.py
@@ -20,3 +20,4 @@ if __name__ == "__main__":
             )
         raise
     execute_from_command_line(sys.argv)
+###

查看当前仓库的状态

(py_3) $ git status
On branch user
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

    modified:   manage.py

no changes added to commit (use "git add" and/or "git commit -a")

此时追踪到了你的修改  使用git add 可以将修改添加到本地仓库

(py_3) $ git add manage.py 

使用全部添加

git add .

之后会看到你已经将修改添加到了本地仓库

(py_3) $ git status
On branch user
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

    modified:   manage.py

将你的修改提交到本地仓库

(py_3) $ git commit -m "add my_web"
[user c2eb367] add my_web
 Committer: user <user@userdeMacBook-Pro.local>
Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly. Run the
following command and follow the instructions in your editor to edit
your configuration file:

    git config --global --edit

After doing this, you may fix the identity used for this commit with:

    git commit --amend --reset-author

 1 file changed, 1 insertion(+)

查看提交记录

(py_3) $ git log
commit e1a49ef3c2fb546523f61498d8da42abaf27ff28 (HEAD -> user, master)  #是当前操作的版本号
Author: USER 
Date:   Wed Mar 20 17:53:10 2019 +0800

    add my_web

此时你已经完成了代码的本地仓库推送 fighting~~~

原文地址:https://www.cnblogs.com/yidada/p/10566692.html