forked from rackerlabs/repose
-
Notifications
You must be signed in to change notification settings - Fork 1
/
git-cheat-sheet.txt
164 lines (94 loc) · 4.22 KB
/
git-cheat-sheet.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
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
160
161
162
163
164
Hopper's Helpful Handle for New Git Users
Glossary
VCS (Version Control System): A version control system is a system
designed to track changes in a given set of data. In most cases this
data set is a code base.
Repository (repositories, repo, repos): A Git repository contains all of
the project branches, their change histories as well as their contents.
Git repositories are different from a traditional VCS in the sense that
everyone has a full "cloned" copy of the entire repository - including
everything inside of it.
URI (Uniform Resource Identifier): A URI is an identifier that may tell
a system where and how to access a resource.
<>: Anything contained within angle brackets '<' and '>' are values you
should fill in.
Getting a new Git repository
============================
Step One: Getting the code
Before we can do any operations we first must obtain a copy of the
repository.
Notes: You must obtain a repository URI before this step!
Command: git clone <repository-uri>
Common Errors
access denied: pubkey: This error is most common if the server you're
talking to does not know who you are. If you encounter this error, verify
with the owner of the repository or server that you have been added
correctly.
Step Two: Creating your own sandbox
Git tracks multiple tracks of changes called branches. It is highly
recommended that you create your own branch. By creating your own branch
you isolate your changes. This means that you cannot damage anyone
else's working state. In addition, this also means it's much easier for
someone to extract the changes you have made.
Note: Your branch name will typically be your username. Branches can be
named anything, however!
Command: git branch <branch-name>
Common Errors
Step Three: Stepping into your new sandbox
Before we can start working in our sandbox, we first have to tell Git
that we're stepping into it to work.
Command: git checkout <branch-name>
Common Errors
Getting Changes
===============
Pulling
Since Git tracks every branch that every user works on, when you tell Git
to pull down changes others have made in the repo, you must let Git know
which branch you want to update from.
Typically you will always pull from the 'master' branch. The master
branch represents the canonical view of the codebase as managed by the
owner of the master branch.
When you or anyone else commits changes to the repository they must be
merged into this master branch so that everyone else can get your
changes.
Git can pull from any branch, however - it's simply most common to pull
from the master branch.
Command: git pull origin master
Common Errors
Merge Conflicts
Adding Changes
==============
Step 1: Staging Changes
Git is aware of most of the changes you make in your repository and will
attempt to track them to the best of its ability. When it comes time to
commit your changes, however, you must tell Git what exactly to commit
from the things that changed.
The following commands will add all of your changes to 'staging' and
mark them ready for commit.
Command: git add .
Command: git add -u .
Step 2: Committing Changes
Now that we've identified what changes we want to make, we must tell Git to commit them and preserve these changes.
Note: It's always important to add a meaningful message to your commit
which is done with the command line option '-m' - Keep in mind that Git
will not let you commit without a message. Empty messages are strongly
discouraged.
Command: git commit -m '<your-message>'
Pushing Changes
===============
Your local copy of the Git repository is now aware of your changes and
has recorded them. Now it's time to send them off so that other users
can see your changes and pull from your branch.
Step 1: Refresh from Master
It is always important to make sure that you have the latest changes
from the master branch. By doing this, you guarantee for the owner of the
master branch that, when they pull your changes in, it won't damage the
master branch's current state.
Command: git pull origin master
Step 2: Pushing to Origin
Now that we've got the latest changes pulled into our branch, we can
push our change-set to the server.
Command: git push origin <branch-name>
Further Reading
==============
http://www.ndpsoftware.com/Git-cheatsheet.html