[Git] commonly used commands connection GitHub

Transfer: https://www.cnblogs.com/binglong180/p/8001487.html

Essay Category

1, if you insert the following errors may try

Copy the code

$ git push -u origin master
To https://github.com/binglong180/loginNew.git
 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'https://github.com/binglong180/loginNew.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

Copy the code

command:

$ git pull --rebase origin master

2, add the update to GetHub (not the first)

$ git push origin master 

If this is the first time to establish contact

$ git remote add origin [email protected]/你的github用户名/仓库名.git  //这个一般在GitHub新建了项目后直接使用就好
$ git push -u origin master

Git common operations command:

1) remote repository related commands

The detection Warehouse: $ git clone git: //github.com/jquery/jquery.git

View remote repository: $ git remote -v

Adding a remote repository: $ git remote add [name] [url]

Delete remote repository: $ git remote rm [name]

Modify remote repository: $ git remote set-url --push [name] [newUrl]

Pull the remote repository: $ git pull [remoteName] [localBranchName]

Push the remote repository: $ git push [remoteName] [localBranchName]

 

* If you want a local branch of a test submitted to a remote warehouse, and the master branch as the remote repository, or as another branch called test, as follows:

$ Git push origin test: master // submitted to the local branch as a test of remote master branch

$ Git push origin test: test // submitted to the local branch as a test test remote branch

 

2) branches (Branch) operation related command

Check local branch: $ git branch

View remote branch: $ git branch -r

Create a local branch: $ git branch [name] ---- Note After you create a new branch will not automatically switch to the current branch

Handover branch: $ git checkout [name]

Create a new branch and switch immediately to the new branch: $ git checkout -b [name]

Delete branch: $ git branch -d [name] ---- -d option to only delete the branch has been involved in the merger, the merger for the No branch can not be deleted. If you want to forcibly remove a branch, you can use the -D option

Merge branch: $ git merge [name] ---- branch will merge with the current branch name of [name]

To create a remote branch (local branch push to remote): $ git push origin [name]

To delete a remote branch: $ git push origin: heads / [name] or $ gitpush origin: [name] 

 

* Create an empty branch :( remember to submit changes to your current branch before executing the command, otherwise it will be forced to delete clean and did not have to regret)

$git symbolic-ref HEAD refs/heads/[name]

$rm .git/index

$git clean -fdx

 

3) version (tag) related to the operation command

View version: $ git tag

Create a version: $ git tag [name]

Delete version: $ git tag -d [name]

View Remote version: $ git tag -r

Create a remote version (the local version of the push to remote): $ git push origin [name]

Delete the remote version: $ git push origin: refs / tags / [name]

tag consolidate the remote repository to local: $ git pull origin --tags

Upload a tag to a remote repository: $ git push origin --tags

Creating an annotated tag: $ git tag -a [name] -m 'yourMessage'

 

4) submodule (submodule) related to the operation command

Add sub-modules: $ git submodule add [url] [path]

   如: $ git submodule add git: //github.com/soberh/ui-libs.git src / main / webapp / ui-libs

Initialization sub-module: $ git submodule init ---- only run once on the line at the first detection of a warehouse

Update sub-modules: $ git submodule update ---- switch after each update or branches are needed to run it

Delete sub-module :( four steps to go oh)

 1) $ git rm --cached [path]

 2) Edit ".gitmodules" file, sub-module configuration node removed

 3) Edit ".git / config" file, delete the sub-node configuration module

 4) Manually delete the remaining sub-module directory

 

5) Ignore some files, folders are not submitted

Creating a warehouse in the root directory named ".gitignore" file, write unnecessary folders or file, each element per line, like this

target

bin

*.db

 

 

 

 

=====================

Git commonly used commands

View all local branches git branch
git status to view the current status of 
git commit submit 
git branch -a view all branches
git branch -r to see all the local branches
git commit -am "init" and submit annotated 
git remote add origin [email protected] : ndshow
git the push origin Master file to push to the server 
git remote show origin displays the remote repository origin in the resources 
git the push origin Master: Develop
git the push origin Master: hb-dev the library on the local library and server associate 
git checkout --track origin / dev dev switch to remote branch
git branch -D master develop delete local library Develop
git Checkout -b dev build a new local branch dev
git merge Origin / dev dev branch will merge with the current branch
git checkout dev switch dev to a local branch
git remote show viewing the remote repository
. git the Add
git RM file name (including the path) delete a file from the git
git clone git: //github.com/schacon/grit.git on the code from the server to pull down the
git config --list to see all the users
git ls-files watch has been submitted
git rm [file name] to delete a file
git commit -a commit the current repos of all changes
git add [file name] add a file to the index git
git commit when you use -v -v parameter can see the difference commit
git commit -m "This is the message describing the commit "to add a commit
git commit -a -a representative of add, all the change in the git index added and then commit
git commit -a -v generally commit command
git log to see your commit log
git diff to see the staging of yet update
git rm aa remove files (deleted from the staging area and workspace)
git RM --cached AA remove files (delete only from the staging area)
git the commit -m "the remove" to remove the file (from the Git delete)
git RM -f AA after forcibly removing the modified file (removed from the staging area and workspace)
git diff --cached or $ git diff --staged view updates have not yet submitted
git stash push to push the file to a temporary space
git stash pop pop temporary space from the file down
---------------------------- -----------------------------
git the Add Remote [email protected] Origin: username / World.git the Hello-
git the Push Origin Master the local project to be submitted to the server
------------------------------------------ -----------------
Git local and server-side synchronization pull
-------------------------- ---------------------------------------
git the Push (remote repository name) (branch name) the local branch pushed up to the server.
Origin serverfix the Push git: awesomebranch
-------------------------------------------- ----------------------
git FETCH is equivalent to get the latest version from remote to local, will not automatically Merge
git the commit -a -m "log_message" (-a All changes are submitted, -m is to add log information) locally modify the sync to the server:
git branch branch_0.1 master created branch_0.1 branch from the main branch master
git branch -m branch_0.1 branch_1.0 the branch_0.1 rename branch_1.0
Git Checkout branch_1.0 / master switch to branch_1.0 / master branch
du -hs

------------ -----------------------------------------------
mkdir WebApp
cd the WebApp
Git the init
Touch the README
Git the Add the README
Git the commit -m 'First the commit'
Git Remote [email protected] the Add Origin: daixu / WebApp.git
Git Push Master -u Origin

Good text: http: //blog.csdn.net/afei__/article/details/51476529

Reference document: http: //www.jianshu.com/p/5e841bfa924b

Tutorial: https: //www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000

 

Category:  Git / GitHub

Guess you like

Origin blog.csdn.net/zzddada/article/details/94645900