Common Git commands personal summary

Common Git commands summary

1. Name and configure a global user E-mail

$ git config --global user.name “Your Name”
$ git config --global user.email “[email protected]

2. Initialize the warehouse

git init

3. Add files to the Git repository

git add
Tip: it can be used repeatedly to add multiple files;

4. Add the file submitted to the Git repository

git commit -m "commit"

5. Check the current state of the repository

git status

6. Compare modify the current file

$ git diff

7. Review the history submit records:

git log --pretty=oneline

8. fallback version

$ git reset --hard HEAD^

9. Check the operation command history record

$ Go reflog

10.diff file

git diff HEAD –

11. Discard changes to the workspace

$ git checkout –

12. discard the file staging area

$ git reset HEAD

13. Delete Files

$ rm

14. Create SSH key

$ ssh-keygen -t rsa -C “[email protected]

15. Collaboration with the remote warehouse

$ git remote add origin [email protected]:jieliuGG.git

  1. Delete local and remote database library association:
    $ git Remote RM Origin
  2. Pushed to the remote repository
    $ git push -u origin master
    Note: The first submission need to add a parameter -u, the future does not need
  3. Clone a remote repository
    $ git clone [email protected]: jieliuGG.git

16.Git Branch Management

  1. Creating a branch Branch1
    $ git Branch Branch1
  2. Switch to branch1 branch:
    $ Git Checkout branch1
  3. Create and switch to branch1 branch:
    $ git Checkout -b branch1
  4. View branch:
    $ git Branch
  5. Branch to merge branch1 Master:
    $ git Merge branch1
  6. Delete branch:
    $ git Branch -d Branch1

17. Review the history submitted

$ git log

Figure 18. View branches merge

git log --graph

19. Merge Branches

$ git merge --no-ff -m “merge” branch1

20. Save your work site

$ git stash

21. discard a branch had not been merged

$ git branch -D

22. View information about the remote repository

$ git remote -v

23. Push branch

  1. Push master to the remote repository
    $ git push origin master
  2. Branch1 push to a remote repository
    $ git push origin branch1

24. Create a local branch

$ git checkout -b branch1 origin/branch1

25. Specify local branch1 branch and remote origin / branch1 branch link

$ git branch --set-upstream branch1 origin/branch1

26. Create a label

$ Git tag

  1. View all tags:
    $ git Tag
  2. Look at the label information:
    $ git Show
  3. Create a label with instructions, with the specified tag name -a, -m specify caption, the above mentioned id 123456 to the commit:
    $ git Tag v1.0 -a -m "V1.0 Released" 123456

27. Remove label:

$ Git tag -d
delete the label remote repository:

  1. First remove the local tag: $ git tag -d V1.0
  2. Push again be deleted: $ git push origin: refs / tags / V1.0

28. Push the label to the remote database:

$ Git push origin
to push all the tags to the remote repository:
$ git push origin the --tags

29. Custom settings Git

Git display color, the command output will look clearer eye-catching:
$ git config to true --global color.ui

30. Set command aliases:

$ git config --global alias.st status

Published 10 original articles · won praise 1 · views 129

Guess you like

Origin blog.csdn.net/weixin_45912307/article/details/103869137