Skip to end of metadata

Go to start of metadata

Here is a list of some basic Git commands to get you going with Git.

For more detail, check out the  Atlassian Git Tutorials  for a visual introduction to Git commands and workflows, including examples.

Git task Notes Git commands
Tell Git who you are

Configure the author name and email address to be used with your commits.

Note that Git strips some characters (for example trailing periods) from user.name.

git config --global user.name "Sam Smith"

git config --global user.email sam@example.com

Create a new local repository

 
git init

Check out a repository

Create a working copy of a local repository:
git clone /path/to/repository
For a remote server, use:
git clone username@host:/path/to/repository

Add files

Add one or more files to staging (index):
git add <filename>

git add *

Commit

Commit changes to head (but not yet to the remote repository):
git commit -m "Commit message"
Commit any files you've added with git add, and also commit any files you've changed since then:
git commit -a

Push

Send changes to the master branch of your remote repository:
git push origin master
Status
List the files you've changed and those you still need to add or commit:
git status

Connect to a remote repository

If you haven't connected your local repository to a remote server, add the server to be able to push to it:

git remote add origin <server>
List all currently configured remote repositories: git remote -v

Branches

Create a new branch and switch to it:
git checkout -b <branchname>
Switch from one branch to another:
git checkout <branchname>
List all the branches in your repo, and also tell you what branch you're currently in:
git branch
Delete the feature branch:
git branch -d <branchname>
Push the branch to your remote repository, so others can use it:
git push origin <branchname>
Push all branches to your remote repository:
git push --all origin
Delete a branch on your remote repository:
git push origin :<branchname>

Update from the remote repository

Fetch and merge changes on the remote server to your working directory:
git pull
To merge a different branch into your active branch:
git merge <branchname>

View all the merge conflicts:

View the conflicts against the base file:

Preview changes, before merging:

git diff

git diff --base <filename>

git diff <sourcebranch> <targetbranch>
After you have manually resolved any conflicts, you mark the changed file:
git add <filename>

Tags

You can use tagging to mark a significant changeset, such as a release:
git tag 1.0.0 <commitID>
CommitId is the leading characters of the changeset ID, up to 10, but must be unique. Get the ID using:
git log
Push all tags to remote repository:
git push --tags origin

Undo local changes

If you mess up, you can replace the changes in your working tree with the last content in head:

Changes already added to the index, as well as new files, will be kept.

git checkout -- <filename>
Instead, to drop all your local changes and commits, fetch the latest history from the server and point your local master branch at it, do this:
git fetch origin

git reset --hard origin/master

Search

Search the working directory for foo(): git grep "foo()"

Copied from: https://confluence.atlassian.com/display/STASH/Basic+Git+commands

Basic Git commands的更多相关文章

  1. BASIC GIT WORKFLOW

    BASIC GIT WORKFLOW Generalizations You have now been introduced to the fundamental Git workflow. You ...

  2. [label][git-commands] Several Git Commands

    The process of Git commands Operation 1. git commit -m 'fist post' Windows PowerShellCopyright (C) 2 ...

  3. Git Commands Quick Notes

    Fetch This command is to make sure your local repository has the same knowledge of the remote-tracki ...

  4. Git Commands

    Show ssh key file: ssh -v git@github.com

  5. Useful Git Commands for me

    查看Git追踪的文件 git ls-files   移除远程仓库的文件夹 git rm -r --cached some-directory git commit -m "Remove th ...

  6. Very Good Article on How Git Commands Work

    http://stackoverflow.com/questions/30038999/differences-between-commit-commit-and-push-commit-and-sy ...

  7. Git 初始状操作指引

    You have an empty repository To get started you will need to run these commands in your terminal. Ne ...

  8. the core of Git is a simple key-value data store The objects directory stores all the content for your database

    w https://git-scm.com/book/en/v1/Git-Internals-Plumbing-and-Porcelain Git is a content-addressable f ...

  9. flask程序部署在openshift上的一些注意事项

    https://www.openshift.com/blogs/how-to-install-and-configure-a-python-flask-dev-environment-deploy-t ...

随机推荐

  1. Headless Chrome:服务端渲染JS站点的一个方案【上篇】【翻译】

    原文链接:https://developers.google.com/web/tools/puppeteer/articles/ssr 注:由于英文水平有限,没有逐字翻译,可以选择直接阅读原文 tip ...

  2. 实验吧_who are you?(盲注)

    who are you? 翻翻源码,抓抓包,乱试一通都没有什么结果 题目中提示有ip,立马应该联想到X-Forwarded-For 虽然知道是这个方面的题,但完全不知道从何入手,悄咪咪去翻一下wp 才 ...

  3. php文件包含漏洞(input与filter)

    php://input php://input可以读取没有处理过的POST数据.相较于$HTTP_RAW_POST_DATA而言,它给内存带来的压力较小,并且不需要特殊的php.ini设置.php:/ ...

  4. [自用]数论和组合计数类数学相关(定理&证明&板子)

    0 写在前面 本文受 NaVi_Awson 的启发,甚至一些地方直接引用,在此说明. 1 数论 1.0 gcd 1.0.0 gcd $gcd(a,b) = gcd(b,a\;mod\;b)$ 证明:设 ...

  5. 2015 多校联赛 ——HDU5384(AC自动机)

    Sample Input 1 5 6 orz sto kirigiri danganronpa ooooo o kyouko dangan ronpa ooooo ooooo   Sample Out ...

  6. hdu 4578 线段树(标记处理)

    Transformation Time Limit: 15000/8000 MS (Java/Others)    Memory Limit: 65535/65536 K (Java/Others) ...

  7. solr6.6初探之配置篇

    一.solr的简介 1) solr是企业级应用的全文检索项目,它是基于Apache Lucence搜索引擎开发出来的用于搜索的应用工程 2) solr最新版本6.6 下载地址:下载地址 二 启动与配置 ...

  8. 在Unix系统中,主存索引节点和辅存索引节点从内容上比较有什么不同,为什么要设置主存索引节点?

    主存索引节点和辅存索引节点的不同主要体现在:主存索引节点状态:设备号.索引节点号:引用计数. 主存索引节点状态——反映主存索引节点的使用情况.它指示出: 1.  索引节点是否被锁上了: 2.  是否有 ...

  9. A neural chatbot using sequence to sequence model with attentional decoder. This is a fully functional chatbot.

    原项目链接:https://github.com/chiphuyen/stanford-tensorflow-tutorials/tree/master/assignments/chatbot 一个使 ...

  10. 从JVM角度看i++ 与++i

    1.i++和++i的问题 反编译结果为 Code:  0:   iconst_1  1:   istore_1  2:   iinc    1, 1 //这个个指令,把局部变量1,也就是i,增加1,这 ...