-
Notifications
You must be signed in to change notification settings - Fork 13
/
git_script.sh
130 lines (103 loc) · 2.61 KB
/
git_script.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
#!/usr/bin/env bash
## clone the repo
git clone https://github.com/omicscodeathon/gitworkshop.git
# or
# git clone [email protected]:omicscodeathon/gitworkshop.git
## you should see a directory called gitworkshop
ls
cd ./gitworkshop
## look around
ls -a
git status
## look at the history
git log
## we need to configure our git account with this repo
## use github account user name and email address
git config -l
git config user.name <name>
git config user.email <emailaddress>
## let's make a file - substitute your username for <name>
echo "hello" ><name>.txt
cat <name>.txt
git status
git diff
## add the file
git add <name>.txt
git status
git diff
git diff --cached
## now we are going to save/commit our changes
git commit <name>.txt -m "adding my file"
git log
## note that the changes are not yet pushed
git log -p
## q to exit
git log --stat --summary
## make additional change to file
echo "goodbye" >><name>.txt
git diff
## we can either add the file OR use git commit -a
git commit -a
## editor should open, if one does not for you, then
## give the commit message on the command line
git commit -a -m "my commit message"
## now we want to save this commit in the cloud
## ALWAYS pull before you push
git pull
git config --global pull.rebase false
git push
## look at a specific commit
git show 06600b0250aa10f57469cbc4e5698db25129510c
## make a change
echo "mistake" ><name>.txt
cat <name>.txt
git status
git diff
git commit <name>.txt -m "bad commit"
## revert commit to "HEAD" (current state of remote) - note we did not push! once you push it is a lot harder to revert commits esp in shared repo.
git reset HEAD
# or
git reset --hard HEAD
## Branch flow
## pull any changes
git pull
## create a branch
git checkout -b <name>
git status
git branch -a
mkdir <name>
echo "my own folder!" ><name>/file.txt
git commit -a -m "made my own folder"
echo "jump!" ><name>/file.txt
git commit -a -m "made a fix to file"
## pull first!
git pull
git push
## will merge my branch
git checkout main
git merge <name>
gitk
git pull
git push
## optional delete your branch
git branch -d <name>
### Fork on Github and clone locally
# we change to a separate directory just to make sure we don't
# get confused between the shared omicscodeathon repo and our fork
cd
mkdir myfork
cd myfork
git clone https://github.com/<name>/gitworkshop.git
# or
# git clone [email protected]:<name>/gitworkshop.git
ls
cd gitworkshop/
git config -l --list
git config user.name <name>
git config user.email <emailaddress>
### Make a change to someone else's file
echo "my changes" >>README.md
git commit README.md -m "my suggested changes"
git status
git pull
git push