Git Common Commands Cheat Sheet (Part 2)
Machine-translated (anthropic, claude-haiku-5-5) from the Chinese original. Read the original in 中文
git branch lists all local branches
git status shows the current status
git commit commits
git branch -a lists all branches
git branch -r lists all remote branches
git commit -am "init" commits and adds a message
git remote add origin [email protected]:ndshow
git push origin master pushes files to the server
git remote show origin shows the resources in the remote repository origin
git push origin master:develop
git push origin master:hb-dev associates the local repository with the repository on the server
git checkout --track origin/dev switches to the remote dev branch
git branch -D master develop deletes the local develop branch
git checkout -b dev creates a new local branch dev
git merge origin/dev merges branch origin/dev into the current branch
git checkout dev switches to the local dev branch
git remote show lists remote repositories
git add .
git rm 文件名(包括路径) removes the specified file from git
git clone git://github.com/schacon/grit.git pulls the code down from the server
git config --list lists all users
git ls-files shows files that have already been committed
git rm [file name] deletes a file
git commit -a commits all changes in the current repos
git add [file name] adds a file to the git index
git commit -v when using the -v parameter, you can see the diff of the commit
git commit -m "This is the message describing the commit" adds the commit message
git commit -a -a stands for add, adding all changes to the git index and then committing
git commit -a -v the general commit command
git log shows your commit log
git diff shows updates not yet staged
git rm a.a removes a file (from the staging area and the working directory)
git rm --cached a.a removes a file (only from the staging area)
git commit -m "remove" removes a file (deletes it from Git)
git rm -f a.a forcibly removes a modified file (from the staging area and the working directory)
git diff --cached 或 $ git diff --staged shows updates not yet committed
git stash push pushes files into a temporary stash
git stash pop pops files back out of the temporary stash
git remote add origin [email protected]:username/Hello-World.git
git push origin master pushes the local project to the server
git pull synchronizes local and server
git push (远程仓库名) (分支名) pushes the local branch to the server.
git push origin serverfix:awesomebranch
git fetch is equivalent to getting the latest version from the remote to local, without automatically merging
git commit -a -m "log_message" (-a commits all changes, -m adds the log message) syncs local changes to the server:
git branch branch_0.1 master creates branch_0.1 from the master branch
git branch -m branch_0.1 branch_1.0 renames branch_0.1 to branch_1.0
git checkout branch_1.0/master switches to the branch_1.0/master branch
du -hs
git branch deletes a remote branch
git push origin :branch_remote_name
git branch -r -d branch_remote_name
Initialize a repository and commit it to the remote server
mkdir WebApp
cd WebApp
git init 本地初始化
touch README
git add README 添加文件
git commit -m 'first commit'
git remote add origin [email protected]:daixu/WebApp.gitAdd a remote server
The command above adds a remote server repository with URL [email protected]:daixu/WebApp.git and name origin; afterwards you only need to use the alias origin when pushing code.
Comments