forked from b-trav/GitTutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Git Tutorial.py
163 lines (88 loc) · 3.41 KB
/
Git Tutorial.py
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
159
# coding: utf-8
# # Git Tutorial
#
# 2/3/2018
# This notebook contains a very brief introduction to Git.
#
# Git is a very useful and powerful version control system
#
# Git is **NOT** very user-friendly
#
# There are a number of websites and programs that attempt to make git more user friendly
# ## Resources
# - https://try.github.io/ - cool site to introduce you to git
# - https://git-scm.com/doc - Official documentation
# - https://git-scm.com/book/en/v2 - Free Git Book
# ## Installing git
# Go to https://git-scm.com/ and install Git for your particular operating system
# ## Setting up git
# Open up a terminal window - this will depend on your operating system.
# - Windows: start GitBash
# - Linux: open a terminal
# - OS X: open a terminal???
# - ChromsOS : In developer mode, type CLT-ALT-T
# In[2]:
get_ipython().getoutput('git config --list')
# You want to store your username and email address:
# ```
# git config --global user.name "John Doe"
# git config --global user.email [email protected]
# ```
# ## Github
# [Github](https://github.com) is a website that allows you to easily create public git repositories. Students are also able to create private git repositories.
#
# You should sign up to github when you have the chance, however you do not need to for the next step.
#
# Clone the repository containing this document:
#
# ```
# git clone https://github.com/b-trav/GitTutorial.git
# ```
# ## Repository
# - A repository is a store of all the versions of all the files in a git project (directory).
# - A repository can either be a _working_ repository, or a _bare_ repository.
# - Working repositories have all your files in them, but they also have a sub-directory called `.git` which contains all the versions of your work.
# - A bare repository is simply the .git folder on its own - normally called `ProjectName.git`
# ## Cloning a repository
# ```
# git clone https://github.com/b-trav/GitTutorial.git
# ```
# ## Creating a repository
# Rather than cloning a repository, you can make your current directory into a git project by simply typing:
# ```
# git init
# ```
# ## Checking the status of a repository
# In[8]:
get_ipython().system('git status')
# ## Adding files
# In[4]:
get_ipython().system('git add Git*')
# ## Committing files
# In[5]:
get_ipython().system('git commit -m "Initial commit of this repository. Committing the Jupyter notebook containing a tutorial about git."')
# ## Ignoring files
# There are often files in git that you do not want versioned. These might include binary files from a compiler, unnecessary backup files, or sensitive files containing usernames or passwords.
#
# Jupyter creates a directory call `.ipynb_checkpoints/` which stores info about your current notebook. We do not need to version this file, so let's ignore it.
#
# We ignore files by simply listing them in a special file called `.gitignore`.
#
# In[6]:
get_ipython().system('echo ".ipynb_checkpoints/" >> .gitignore')
# In[7]:
get_ipython().system('cat .gitignore')
# In[9]:
get_ipython().system('git add .gitignore')
# In[10]:
get_ipython().system('git commit -m "Adding .gitignore file, and ignoring ipynb_checkpoints."')
# In[11]:
get_ipython().system('git status')
# ## Pushing files
# In[13]:
get_ipython().system('git push origin master')
# ## Pulling files
# In[14]:
get_ipython().system('git pull origin master')
# ## Branches, merging and much more
# In[ ]: