Simple git use command

Client version:
C:\Users\xp>git --version
git version 2.14.1.windows.1

The git client is installed by Baidu.

1. Configure a nickname for updating version tracking.
1. Configure the nickname
git bash and execute the following command:
(1) git config --global user.name "xiaoping"
(2) git config --global user.email "[email protected]"
View through the command git config -l Configured user name and email information
2. Generate key pair
Open git bash, enter the command and press Enter.
ssh-keygen -t rsa -C "[email protected]"
Second, clone the project from the remote
git bash
git clone git [email protected]: warehouse address.
Example: git clone [email protected]:data/xx.git
3. Pull and push operations
Developers ' local operations:
1. Update the code from the remote repository dev:
git pull <remote host> <remote branch name>: <local branch name>
Example: E:\workspace\git_test>git pull origin dev:master

remote: Counting objects: 17, done.
remote: Compressing objects: 100% (6/6), done.
remote: Total 9 (delta 3), reused 0 (delta 0)
Unpacking objects: 100% (9/9), done.
From 123.206.51.64:data/git_test
   5218488..e28fd78  dev        -> master
 * [new branch]      dev        -> origin/dev
warning: fetch updated the current branch head.
fast-forwarding your working tree from
commit 521848830e57c8ae1f45cccb5fd91dd2de077c5b.
Already up-to-date.
2.本地提交代码到远程仓库dev分支上
查看状态
E:\git_workspace\demo>git status
On branch master
Your branch is up-to-date with 'origin/master'.
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

        modified:   demo/src/main/java/com/exception/EmsException.java

Submission step 1:
E:\git_workspace\demo>git add .
Submission step 2:
E:\git_workspace\demo>git commit -m "Submit description information, you must write"
[master 34ecceb] Submit description information, you must write
 1 file changed, 3 insertions(+), 1 deletion(-)
Commit step 3:
git push <remote host name> <local branch name>:<remote branch name>
Example:
E:\test\git_test>git push origin master: dev

Counting objects: 9, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (6/6), done.
Writing objects: 100% (9/9), 615 bytes | 307.00 KiB/s, done.
Total 9 (delta 3), reused 0 (delta 0)
To 123.206.51.64:data/git_test.git
   5218488..e28fd78 master -> dev

If you can't remember the order of push and pull remote branch name and local branch name, you can set the default branch for git push and pull:
git branch --set-upstream-to=origin/<remote branch name> <local branch name>

Example :
D:\workspace\demo>git branch --set-upstream-to=origin/dev master
Branch master set up to track remote branch dev from origin.
This way I set the default remote branch for push and pull of my local master branch is dev.

2. The operation of the administrator's remote warehouse
1. After the operation of creating a warehouse git init
    , as long as there is a hidden file of .git, it is an empty warehouse at this time. Using git branch, you can't see any branches.
2. Create a local project and push it to the remote warehouse.
    Then you will find an error.
remote: error: refusing to update checked out branch: refs/heads/master
remote: error: By default, updating the current branch in a non-bare repository
remote: error: is denied, because it will make the index and work tree inconsistent
remote: error: with what you pushed, and will require 'git reset --hard' to match
remote: error: the work tree to HEAD.
remote: error:
remote: error: You can set 'receive.denyCurrentBranch' configuration variable to
remote: error: 'ignore' or 'warn' in the remote repository to allow pushing into
remote: error: its current branch; however, this is not recommended unless you
remote: error: arranged to update its work tree to match what you pushed in some
remote: error: other way.
remote: error:
remote: error: To squelch this message and still keep the default behaviour, set
remote: error: 'receive.denyCurrentBranch' configuration variable to 'refuse'.
To 127.0.0.1:data/git_test.git
 ! [remote rejected] master ->master (branch is currently checked out)
error: failed to push some refs to '[email protected]:data/git_test.git'

Reason: This is because git rejects the push operation by default and requires To make settings, modify the .git/config file and add the following code:
    [receive]
    denyCurrentBranch = ignore
After the operation is successfully submitted, you can enter git branch on the remote repository and you will see a *master. At this time, the master branch has
3. Create a dev branch:
    git branch dev (create dev)/git checkout -b dev (create and switch to dev)
4. The remote repository cannot allow developers to push at will, so delete 2.
5. The branch is merged into master demo.git
]# pwd
/home/git/data/demo.git
[root@t2 demo.git]#View

the current branch
[ root@t2 demo.git]# git branch
* dev
  master
[root@t2 demo.git]#

If not switch to the master branch
[root@t2 demo.git]# git checkout master
Switched to branch 'master'
[root@t2 demo.git]# git branch
  dev
* master
[root@t2 demo.git]#

Merge the branch Go to master branch
[root@t2 demo.git]# git merge dev
Updating 1b85a27..1d471fe
Fast-forward
 demo/.mvn/wrapper/maven-wrapper.jar | Bin 47610 -> 0 bytes
 demo/.mvn/wrapper/maven -wrapper.properties | 1 -
 demo/mvnw | 225 ---------------------
 demo/mvnw.cmd | 143 ---------- ---
 .../demo/Controller/TestController.java | 15 ++
 5 files changed, 15 insertions(+), 369 deletions(-)
 delete mode 100644 demo/.mvn/wrapper/maven-wrapper.jar
 delete mode 100644 demo/.mvn/wrapper/maven-wrapper.properties
 delete mode 100644 demo/mvnw
 delete mode 100644 demo/mvnw.cmd
 create mode 100644 demo/src/main/java/com/Controller/TestController.java
[root@t2 demo.git]#





Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324799679&siteId=291194637