-
Notifications
You must be signed in to change notification settings - Fork 0
/
git_commands.txt
118 lines (88 loc) · 3.52 KB
/
git_commands.txt
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
SETUP AND INIT
* git init
* Initialize a new Git repo
* git clone
* Clone an existing repo from Github to the local machine
STAGE AND SNAPSHOT
* git status
* Check the status of files in the working directory and staging area
* git add
* add files to the staging area before committing
* git add -A: to stage new, modified, and deleted files across the repository
* git add .: to stage only new and modified files in the current and sub-directories.
* git add -u: to stage only modified and deleted files across the repository
* git commit
* commit changes in the staging area to the repo with a msg
* git commit -m 'commit message': commit all staged changes
* git commit -am 'commit message': commit all tracked changes
* git commit --amend: modify the last commit
BRANCHES
* git branch
* list, create, or delete branch
* git branch -a: list all the branches
* git branch branch_name: create a new branch but doesn't checkout
* git branch -d branch_name: delete a branch if there is no unmerged changes
* git branch -D branch_name: delete a branch forcefully
* git branch -m branch_name: rename the branch name
* git branch --set-upstream-to remote_branch: sets the upstream branch to the specified remote branch
* git checkout
* create branch, switch b/w branches, or restore working directory files
* git checkout -b branch_name: create and switch to new branch
* git checkout branch_name: switch to an existing branch
* git checkout <commit>: switches working directory to specific commit
SHARE AND UPDATE
* git remote add [ref] [url]
* add remote repo
* git push
* push commits from the local repo to a remote repo
* git pull
* Fetch and merge changes from a remote repo into a local branch
* fetch + merge, for a single branch
* git fetch
* Fetch the remote changes but do not merge
* git merge
* Merge changes from one branch into another
TEMPORARY COMMITS
* git stash
* stash changes
* git stash pop
* apply and discard the stash
* git stash apply
* apply the stash
* git stash drop
* discard stash
REWRITE HISTORY
* git rebase
* rebase the current branch
* git rebase -i: rebase interactively, rewrite commit history
* git rebase branch_name: rebase the current branch onto given branch
* git reset
* unstage the changes
* git reset HEAD~1: Undo the last commit, preserving changes locally
* git reset --soft HEAD~1: undo the last commit, but keep the changes staged
* git reset --mixed HEAD~1: undo the last commit, but unstage the changes
* git reset --hard: Completely remove the last commit and changes
* git revert
* git revert commit_id: create a new commit that undoes the changes of a specific commit
* git cherry-pick
* Apply changes from a specific commit (from another branch) to the current branch, depending on the similarity b/w the branches, if significant differences exist conflict will come.
INSPECT AND COMPARE
* git log
* view the commit history
* git log -n <number>
* git log --author=<name>
* git log --since=<data> and --until=<date>
* git log --grep=<pattern>
* git log --stat
* git log --graph
* git diff
* show changes b/w working directory and staged area
* git diff --stat: show the summary of the changes
* git diff --name-only: shown only the names of changed file
* git diff <branch_name>/<file_name>
* git diff --staged/--cached: compare the staging area with the last commit
* git diff <commit>: compare the working directory with a specific commit
* git diff <commit1> <commit2>: compare the difference b/w two commits
*
* git show <commit>
* show commit details