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. mysql sql语句执行时是否使用索引检查方法

    在日常开发中,使用到的数据表经常都会有索引,这些索引可能是开发人员/DBA建表时创建的,也可能是在使用过程中新增的.合理的使用索引,可以加快数据库查询速度.然而,在实际开发工作中,会出现有些sql语句 ...

  2. Linux服务器断电导致挂载及xfs文件损坏的修复方法

    系统文件损坏后进入紧急修复模式,无法进行维护工作 welcome to emergency mode!after logging in ,type "journalctl -xb" ...

  3. [TJOI 2013]单词

    Description 题库链接 给出一篇文章的所有单词,询问每个单词出现的次数. 单词总长 \(\leq 10^6\) Solution 算是 \(AC\) 自动机的板子,注意拼成文章的时候要在单词 ...

  4. [JLOI 2015]城池攻占

    Description 小铭铭最近获得了一副新的桌游,游戏中需要用 m 个骑士攻占 n 个城池. 这 n 个城池用 1 到 n 的整数表示.除 1 号城池外,城池 i 会受到另一座城池 fi 的管辖, ...

  5. weak_ptr解决shared_ptr环状引用所引起的内存泄漏[转]

    转载:http://blog.csdn.net/liuzhi1218/article/details/6993135 循环引用: 引用计数是一种便利的内存管理机制,但它有一个很大的缺点,那就是不能管理 ...

  6. 【NOIP2016】换教室

    题目描述 对于刚上大学的牛牛来说, 他面临的第一个问题是如何根据实际情况中情合适的课程. 在可以选择的课程中,有2n节课程安排在n个时间段上.在第 i ( 1≤ i≤n)个时同段上, 两节内容相同的课 ...

  7. [LSGDOJ 1299]搭配买卖

    题目描述 joe觉得云朵很美,决定去山上的商店买一些云朵.商店里有n多云,云朵被编号为1,2,……,n,并且每朵云都有一个价值.但商店老板跟他说,一些云朵要搭配来买才好,所以买一朵云则与这多云有搭配的 ...

  8. 【USACO】AC自动机

    Description 对,这就是裸的AC自动机. 要求:在规定时间内统计出模版字符串在文本中出现的次数. Input 第一行:模版字符串的个数N. 第2->N+1行:N个字符串.(每个模版字符 ...

  9. ●BZOJ 2209 [Jsoi2011]括号序列

    题链: http://www.lydsy.com/JudgeOnline/problem.php?id=2209 题解: Splay 很好的题,但是把智障的我给恶心到了...   首先不难发现,最后没 ...

  10. 深入分析synchronized的实现原理

    基础概念 synchronized可以保证方法或者代码块在运行时,同一时刻只有一个方法可以进入到临界区,同时可以保证共享变量对内存可见性. Java中每一个对象都可以作为锁,这是synchronize ...