Git常用命令

拉取已经创建的仓库

前提是已经配置过git的ssh登录

Command Description
git init Initialize a local Git repository
git clone ssh://git@github.com/[username]/[repository-name].git Create a local copy of a remote repository

基础快照命令

Command Description
git status Check status
git add [file-name.txt] Add a file to the staging area
git add -A Add all new and changed files to the staging area
git commit -m "[commit message]" Commit changes
git rm -r [file-name.txt] Remove a file (or folder)

分支 & 合并

Command Description
git branch List branches (the asterisk denotes the current branch)
git branch -a List all branches (local and remote)
git branch [branch name] Create a new branch
git branch -d [branch name] Delete a branch
git push origin --delete [branchName] Delete a remote branch
git checkout -b [branch name] Create a new branch and switch to it
git checkout -b [branch name] origin/[branch name] Clone a remote branch and switch to it
git checkout [branch name] Switch to a branch
git checkout - Switch to the branch last checked out
git checkout -- [file-name.txt] Discard changes to a file
git merge [branch name] Merge a branch into the active branch
git merge [source branch] [target branch] Merge a branch into a target branch
git stash Stash changes in a dirty working directory
git stash clear Remove all stashed entries

分享 & 更新项目

Command Description
git push origin [branch name] Push a branch to your remote repository
git push -u origin [branch name] Push changes to remote repository (and remember the branch)
git push Push changes to remote repository (remembered branch)
git push origin --delete [branch name] Delete a remote branch
git pull Update local repository to the newest commit
git pull origin [branch name] Pull changes from remote repository
git remote add origin ssh://git@github.com/[username]/[repository-name].git Add a remote repository
git remote set-url origin ssh://git@github.com/[username]/[repository-name].git Set a repository's origin branch to SSH

审查历史 & 对比

Command Description
git log View changes
git log --summary View changes (detailed)
git diff [source branch] [target branch] Preview changes before merging
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 我的常用: ===================================** 撤销工作修改:**1、gi...
    ddai_Q阅读 767评论 0 5
  • 配置 首先是配置帐号信息 ssh -T git@github.com#登陆github 修改项目中的个人信息 1 ...
    rochuan阅读 751评论 1 1
  • 配置 首先是配置帐号信息ssh -T git@github.com # 登陆 github 修改项目中的个人信息 ...
    guanguans阅读 759评论 0 3
  • 查看、添加、提交、删除、找回,重置修改文件 git help # 显示command的help git sho...
    Swiftor阅读 2,139评论 0 2
  • 昨晚和友人餐叙,谈到一个话题,第一次听觉得很有道理,今早醒来回味觉得有点矫情,然后又想了想,又重新感觉有道理。 这...
    望京詹姆士阅读 346评论 0 2