-
Notifications
You must be signed in to change notification settings - Fork 342
/
git.sh
160 lines (86 loc) · 2.67 KB
/
git.sh
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# this is not an executable script ;)
# generate .gitignore files at https://www.gitignore.io/
# clone an existing repository
git clone git://github.com/tacksoo/bash_basics.git
# or start tracking a project
git init
# show current git configuration
git config -l
# set user name and e-mail address
git config --global user.name "Default User"
git config --global user.email "[email protected]"
# show remote repositories
git remote -v
# add a remote repository
git remote add origin git://github.com/someone/somerepo.git
# get code from remote
git fetch origin
# merge remote's code with the code you have
git merge origin
# start tracking a file
git add readme.txt
# see what changes were made
git status
# commit the change
git commit -m 'added readme'
# add and commit
git commit -am 'modified readme'
# compare the working directory with what's on the staging area
git diff
# compare the stages changes to the last commit
git diff --staged
# remove a file from git
rm readme.txt
git rm readme.txt
# move files in git
git mv from.txt to.txt
# remove latest commit (data loss!)
git reset --hard HEAD~1
# undo latest commit (keep changes in index)
git reset --soft HEAD~1
# squash last three commits into one interactively
# need to specify which commits to squash
git rebase -i HEAD~3
# look at past commit messages
git log
# show one line summary of the commits
git log --pretty=oneline
# show tree-like view of the commits
git log --graph --oneline
# show summary of commit per user
git shortlog -s
# show the total number of commits
git rev-list HEAD --count
# unstage a staged file
git reset HEAD somefile.txt
# revert back to previously commited state
git checkout -- somefile.txt
# create a branch for tracking a remote repository
git checkout -b somebodyelse-master master
# pull the changes in the remote repository
git pull https://github.com/somebodyelse/some-repo.git master
# merge the changes and update your remote
git checkout master
git merge somebodyelse-master
git push origin master
# delete branch
git branch -d somebodyelse-master
# show all local and remote branch
git branch -a
# delete a branch on remote origin
git push origin --delete some-branch
# if you refer to that remote repository often, add it as one of your remotes
# I will refer to it as 'upstream'
git remote add upstream https://github.com/somebodyelse/some-repo.git
# stash your changes
git stash
#
# apply latest stash
git stash apply
git stash pop # this deletes the stash and then deletes it
# remove stash using its name
git stash drop stash@{0}
# clear stash
git stash clear
# stop tracking changes of a file
git update-index --assume-unchanged file.txt