Git Common operations Collection

Source: Internet
Author: User
Tags commit diff reset ssh how to use git

1. about how to create a branch other than the main branch, and the submitted code is also placed in a remote branch of the same name.

Create a new branch locally
git branch dikang_branch 
git branch-a//view all local and remote branches, the remote branch will flag
git push origin dikang_ in red Branch//push local branch to remote, if there is no corresponding remote branch to create
a new git push--set-upstream origin dikang_branch 
//Create a new branch locally, you must do a remote branch association. If there is no association, Git prompts you to display the Add association in the following operation. The purpose of the association is to operate on a local branch: Git pull, git push, no need to specify a remote branch at the command line
next to any of your actions git push will push to Dikang_branch

2. Delete a remote branch using
Git push origin-delete <branchName> or Git push Origin:<branchname> (pushing an empty branch to a remote branch is actually the equivalent of deleting a remote branch:)

3. View the Origin remote branch details
git remote show origin

4. View the latest commits under the remote branch and branch
Git branch-av

5. View the port and remove the footprint

NETSTAT-TUNPL 
kill-9 (PID)   

6. How to clone a remote Git project locally as well:
+ open git bash,mkdir xxx && cd xxx

git init
git config--global user.name ' andyliwr '
git config--gloabl user.email ' 121960425@qq.com '
git Remote add-f-T Master-m Master Origin https://github.com/Andyliwr/blog.git
Git merge origin

7. If a permission error occurs when cloning a remote project.


Solution :
+ First Look at the local there is no SSH key (generally in/c/users/andyliwr/.ssh/id_rsa.pub)
+ If not, use ssh-keygen-t rsa-c "lidikang@idwzx.com" to create a
+ then use the editor to open/c/users/andyliwr/.ssh/id_rsa.pub, copy the contents to git stash or GitHub website to add SSH key.

8. How to use Git stash to quickly save the content that has been modified, after the other things to restore back.

# ... hack hack hack
... $ git stash
$ edit Emergency fix
$ git commit-a-M "fix in a hurry"
$ git stash pop//or Git stash list view all STA SH, and then git stash apply <stash name> Specify which stash
# ... continue hacking ...

9. If you are modifying the code, but now there is a very important update you need to pull, in order to avoid conflicts you can use:

git stash save ' save-message '
$ git pull
$ git stash pop

10. Git is a big step forward today:
+ Graphical view of submission records
git log--graph--oneline--decorate
Executing git config--global alias.lol "log--pretty=oneline--abbrev-commit--graph--decorate allows you to make a tree view of the commit record in the future just by executing git lol
+ already add but not committed, how to view the modified code
git diff--cached
+ more powerful git show than Git diff
Git show can see that a code change has been submitted in time. Git show head^ See the last modified code, git show head^^ see the last two modified code

11. Set up a small project on the github.com, but in each push, you have to enter the user name and password, it is troublesome
The reason is that using HTTPS mode push to enter Git remote-v inside the terminer, you can see the shape of the return results

Origin Https://github.com/yuquan0821/demo.git (Fetch)
origin https://github.com/yuquan0821/demo.git (push)

Here's how to change it to SSH.

Git remote rm origin
git remote add Origin git@github.com:yuquan0821/demo.git

12. How to rollback local and remote commits

git reset--hard commit_id (available git log–oneline view) # # #本地代码回退
git reset--hard head^//fallback commit
git push origin HEAD --force # # #远程提交回退

git rename branch :
git branch-m devel Develop

15.Refspec matches more than one
This error occurs when you push the branch:

$ Git push origin master
error:src Refspec master matches more than one.
Error:failed to push some refs to ' Ssh://user@host/srv/git/repo

This is because the current GIT project has the same tag version as your current branch name, which is fine if it is not necessary to remove it.

$ git tag
master
tag1
tag2
tag3
tag4
tag-d Master

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.