-
Notifications
You must be signed in to change notification settings - Fork 0
/
git command
77 lines (62 loc) · 3.03 KB
/
git command
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
-> create a new repository on the command line
--
echo "# github-command" >> README.md
git init
git add README.md
git commit -m "first commit"
git branch -M main
git remote add origin https://github.com/Shakilgithub20/github-command.git
git push -u origin main
--
…or push an existing repository from the command line
---
git remote add origin https://github.com/Shakilgithub20/demo.git
git branch -M main
git push -u origin main
---
# Check git user/email name:
-> git config --list
# set git :
-> git config --global user.name <your-name>
-> git config --global user.email <your-email>
-> git config --local user.name <your-name>
-> git config --local user.email <your-email>
# Show
-> git branch # Show all local branches
-> git branch -r # Show all the remote branch
-> git branch -av # Show all local and remote branches
# Create
-> git branch <branch-name> # Create a new branch
-> git checkout -b <branch-name> # Create & checkout to new branch
-> git checkout --orphan <branch-name> # Create a branch with no commit list
# Push
-> git push origin <branchname> # Push to remote branch
# Delete
-> git branch -d <branchname> # Delete the local branch, show a warning
-> git branch -D <branhcname> # Force to delete branch
-> git remote prune origin # Cleanup remote deleted branch
-> git add .
-> git add --all # Add all changes
# Commit
-> git commit -am 'commit message' # Add & commit
-> git commit --allow-empty -m k3; # Commit empty change
-> git cherry-pick <commit-hash> # Take a commit change of another branch
# Amend
-> git add task2.txt # Add any file
-> git commit --amend -m 'new message' # Merge current change to previous commit and will also change the commit hash
# Pull
-> git pull origin <branch-1> # Pull the change of 'branhc-1' in current branch
# Push
-> git push origin <branchame> # Push a branch
-> git push -f origin <branch-name> # Overwrite remote branch (by force)
# Merge
-> git merge origin <branch-1> # Merge remote 'branch-1' with current branch
-> git mergetool
-> git merge --squash <privateFeatureBranch>
# Set local folder to response remote url
git remote set-url origin git@Xyz
-> git checkout <commit-hash> # Go to a specific commit
-> git checkout <branch-name> # Return to present state
-> git checkout <commit-hash> <file-name> # Only a file will go back to specific commit
-> git checkout <branch-name> -f # Return to persent state by force
-> git checkout -- <filename1> <filename2> # Discard all changes of file1 and file2