Basic Git commands

- Created by Paul Watson [Atlassian], last modified on
Nov 25, 2014
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 |
|
git init |
||
| 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 one or more files to staging (index): |
git add <filename> git add * |
|
| 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 |
|
| 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 |
|
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 |
|
| 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> |
|
| 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 <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 |
|
|
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()" |
Basic Git commands的更多相关文章
- BASIC GIT WORKFLOW
BASIC GIT WORKFLOW Generalizations You have now been introduced to the fundamental Git workflow. You ...
- [label][git-commands] Several Git Commands
The process of Git commands Operation 1. git commit -m 'fist post' Windows PowerShellCopyright (C) 2 ...
- Git Commands Quick Notes
Fetch This command is to make sure your local repository has the same knowledge of the remote-tracki ...
- Git Commands
Show ssh key file: ssh -v git@github.com
- Useful Git Commands for me
查看Git追踪的文件 git ls-files 移除远程仓库的文件夹 git rm -r --cached some-directory git commit -m "Remove th ...
- Very Good Article on How Git Commands Work
http://stackoverflow.com/questions/30038999/differences-between-commit-commit-and-push-commit-and-sy ...
- Git 初始状操作指引
You have an empty repository To get started you will need to run these commands in your terminal. Ne ...
- 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 ...
- flask程序部署在openshift上的一些注意事项
https://www.openshift.com/blogs/how-to-install-and-configure-a-python-flask-dev-environment-deploy-t ...
随机推荐
- [LeetCode] Smallest Good Base 最小的好基数
For an integer n, we call k>=2 a good base of n, if all digits of n base k are 1. Now given a str ...
- Cmder Windows 下的终端神器
废话 Windows 下常用的终端有两个,古老的 cmd 和功能强大但你记不住函数的 PowerShell ,两者我都用过一段时间,给我的提体验是功能够用,界面丑陋,虽然 win10 下可以通过调整背 ...
- 使用vba做一个正则表达式提取文本工具
测试中经常会遇到对数据的处理,比如我要删除某些特定数据,数据源是从网页请求中抓取,这时候可能复制下来一大堆内容,其中我们只需要特定的某些部分,笔者通常做法是拷贝到notepad++中处理,结合RegT ...
- python2.7-巡风源码阅读
推荐个脚本示例网站:https://www.programcreek.com/python/example/404/thread.start_new_thread,里面可以搜索函数在代码中的写法,只有 ...
- [HNOI 2010]chorus 合唱队
Description 题库链接 对于一个包含 \(N\) 个整数的数列 \(A\) ,我们可以把它的所有元素加入一个双头队列 \(B\) . 首先 \(A_1\) 作为队列的唯一元素,然后依次加入 ...
- codefroces 55D Beautiful numbers
[Description] 美丽数是指能被它的每一位非0的数字整除的正整数. [Input] 包含若干组数据,每组数据一行两个数n,m,表示求[n,m]之间的美丽数的个数. [output] 对于每组 ...
- ●BZOJ 2434: [Noi2011]阿狸的打字机
●赘述题目 (题意就不赘述了) ●解法: ●我先想的一个比较暴力的方法(要TLE): (ac自动机)先求出last数组(参见刘汝佳的解释:last[j]:表示j节点沿着失配指针往回走时,遇到的下一个单 ...
- SPOJ NSUBSTR
You are given a string S which consists of 250000 lowercase latin letters at most. We define F(x) as ...
- hdu 1394 线段树
Minimum Inversion Number Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java ...
- [bzoj4625][BeiJing2016]水晶
来自FallDream的博客,未经允许,请勿转载,谢谢. 不用惊慌,今天的题都不是小强出的.——融入了无数心血的作品,现在却不得不亲手毁掉,难以体会他的心情啊 .——那也是没有办法的事情,能量共振不消 ...