-
Notifications
You must be signed in to change notification settings - Fork 77
/
git.cheat
134 lines (94 loc) · 3.57 KB
/
git.cheat
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
% git
# Set global git user name
git config --global user.name <name>
# Set global git user email
git config --global user.email <email>
# Initializes a git repository
git init
# Clone a git repository
git clone -b <branch_name> <repository> <clone_directory>
# Shallow clone with depth 1 with all branches and submodules
git clone --depth=1 --no-single-branch --recurse-submodules <repository> <clone_directory>
# Rebase upstream master into local/origin master (use if people don't clone your repository)
git fetch <remote_name>
git checkout master
git rebase <remote_name>/master
git fetch --unshallow origin
git push -f origin master
# Merge upstream master into local/origin master (use if people clone your repository)
git fetch <remote_name>
git checkout master
git merge <remote_name>/master
git fetch --unshallow origin
git push -f origin master
# View all available remote for a git repository
git remote --verbose
# Adds a remote for a git repository
git remote add <remote_name> <remote_url>
# Renames a remote for a git repository
git remote rename <old_remote_name> <new_remote_name>
# Remove a remote for a git repository
git remote remove <remote_name>
# Checkout to branch
git checkout <branch>
# Displays the current status of a git repository
git status
# Displays unstaged changes for file
cd <toplevel_directory>; \
git diff <unstaged_files>
# Stage single or multiple files
cd <toplevel_directory>; \
git add <changed_files>;
# Stage all files in project
git add -A
# Create commit for staged files
git commit -m "<commit_description>"
# Create backdated commit for staged files
git commit --date="<number_of_days_ago> days ago" -m "<commit_description>"
# Pushes committed changes to remote repository
git push -u <remote_name> <branch_name>
# Pushes changes to a remote repository overwriting another branch
git push <remote_name> <branch>:<branch_to_overwrite>
# Overwrites remote branch with local branch changes
git push <remote_name> <branch_name> -f
# Pulls changes to a remote repo to the local repo
git pull --ff-only
# Merges changes on one branch into current branch
git merge <branch_name>
# Abort the current conflict resolution process, and try to reconstruct the pre-merge state.
git merge --abort
# Displays log of commits for a repo
git log
# Displays formatted log of commits for a repo
git log --all --decorate --oneline --graph
# Clear everything
git clean -dxf
# Sign all commits in a branch based on master
git rebase master -S -f
# See all open pull requests of a user on Github
navi fn url::open 'https://github.com/pulls?&q=author:<user>+is:open+is:pr'
# Checkout a branch from a fork
git fetch origin pull/<pr_number>/head:pr/<pr_number> \
&& git checkout pr/<pr_number>
# Add a new module
git submodule add <repository> <path>
# Update module
git submodule update --init
# Update module without init
git submodule update
# Pull all submodules
git submodule foreach git pull origin master
# Update all submodules
git submodule update --init --recursive
# Skip git hooks
git commit --no-verify
# Create new branch from current HEAD
git checkout -b <new_branch_name>
# Remove commits from local repository (destroy changes)
git reset --hard HEAD~<number_of_commits>
# Remove commits from local repository (keep changes)
git reset --soft HEAD~<number_of_commits>
$ branch: git branch | awk '{print $NF}'
$ toplevel_directory: git rev-parse --show-toplevel
$ unstaged_files: git status --untracked-files=no -s --porcelain | awk '{print $NF}' --- --multi true
$ changed_files: git status --untracked-files=all -s --porcelain | awk '{print $NF}' --- --multi true