Configuring Git
一个电脑只用布置一次,设置好后再次使用git 此步骤忽略
git config --global user.name "Yuiko Zhang"
git config user.name
git config --global user.email kk@nyu.edu
git config user.email
user.email 最好使用github 注册的email
如何联系本地文件夹和github repository
How To Update a Github Repository From Your Local Drive
Quick summary:
- Open terminal and enter the folder of the github repository/project you want to update
- Type into terminal: “git add .” and then hit enter
- Type into terminal “git status” and then hit enter (this step is optional)
- Type into terminal “git commit -m ‘type any message here” and then hit enter
- Type into terminal “git push” and then hit enter
团队合作
如果你是领导,首先第一步是需要将合作人员名单加入你的github repository中,使得他们获得github repository 修改权限。
git pull git pull git上的代码拉取到本地更新本地代码。即使你更新了你的文件夹里的内容,也不会对其他内容有所改变。但如果文件夹等结构发生改变,那git pull就会很难成功。适合没有conflict,各自独立文件夹的工作。
创建一个仓库
之前的文档
-
从0开始创建仓库
git init创立git只要做一次 -
从github上克隆一个仓库
git clone url。后台下载全部文件
github 地址位置
这时俩个仓库都是你的了,在你电脑 tips:随时用git status检测文件状态
自己创立git会放置的文件夹。然后git init. 会创立一个.git 的隐形文件。以后在文件夹里git status 会跳出git status。 ls -a 可以看见隐形文件
do not initiate a git repo inside of a git repo. 先用git status 检测一下
Git Add/ Git Commit
git add git commit
Git Add
add specific files to the staging area.
git add file1 file2 Separate files with spaces to add multiple at one.
git add . Stage all changes at once.空格后+ .
Use git status to verify what changes are staged and not staged.
如果手滑加入add错了文件。git reset HEAD <name> 取消add 或者使用git restore --staged <file name>取消add
Git commit
commit changes from the staging area to repository.
git commit will launch a text editor
git commit -m "my message" better method to commit
git commit -am "message" 可以提交没有add的文件
git reset head~ --soft 可以撤销commit
git push commit 后 git push 提交
git log 查看历史提交 可以用git log --graph git log --pretty 修改展示效果
git diff 查看不同(学的还是不是很好)
每一个Git Commit should encompass a single feature, change or fix. In other words, try to keep each commit focused on a single thing.
图片中master 指的是 master branch
git branch
github 远程仓库
git remote add origin <远程仓库http链接> orgin是暂定的远程仓库名字,一般都叫这个名字
git remote 检测remote仓库是否配置成功
git remote rename orgin origin 把remote仓库名称从orgin改为origin
git push origin master 将master branch推送到origin仓库中去
github 用户名和用户密码方式进不去,需要使用github的token 或者使用ssh ssh没看懂。需要自己重看
git Branch 分支
如何查看自己在哪个分支 git log git status git branch --list 查看所有分支,前面带* 的就是现在的分支 git branch BRANCH_NEW_NAME
git checkout new_branch 进入新branch
git checkout -b new_branch2 创立新的分支new_branch2 并切换到new_branch2
合并分支
git merge feature1
附录: clone好的仓库如何上传
git remote 查看是否链接远程仓库
git push --set-upstream origin main origin 远程仓库名称 main branch名称
回车自动github更新文件
git clone文件太大无法下载怎么办: stackoverflow.com/questions/2…
Reference
推荐视频: b站讲解