summaryrefslogtreecommitdiff
path: root/docs/git_howto.txt
blob: ce532d0eef1f0d433ec9400fe1055afd32471b96 (plain)
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
165
166
167
168
169
170
> Hi. I'm on develop branch. I commited change, how can I push it to
> you?

I'll explain the preferred method, instead of the simpler "send me a
patch file". The preferred method has many more benefits for you and me,
and makes integrating other developers changes easier.

This is a bit long winded, but most of it is actually just about
setting up a new remote repository. This setup process is only done
once. The actual "how to share a branch with others" is answered near
the end. So if you know how to setup a forked Github repository, then
just skip to the end.


Using Github
------------
If you cloned from SourceForge or from my GitHub repository, then you
only have "read" access. So you will not be allowed to push changes.

Best is to register with Github (it is free, and very quick). Browse to
my fpGUI repository on Github (it is a mirror of the SourceForge one).

  http://github.com/graemeg/fpGUI

Click the "fork" button. Github will now fork my repository, and you
should end up with a fpGUI repository in your github account.

  NOTE: This fork isn't automatically kept in sync with mine - it is
  your repository - you keep it up to date via 'git push'.

Now back in your Github account, note the read-write URI for the fpGUI
repository. It will be something like...

  git@github.com:<username>/fpGUI.git

Now on your PC, simply add the remote repository (no need to do a new
clone):

  git remote add github <read-write url supplied by Github>

Now you can do a 'git fetch github' or 'git pull github'... If your
repository was up to date, nothing will be updated accept for references
to the branches in the 'github' remote.

If you do a 'git remote' command, you should now see 'origin' and
'github' listed.


Lets do some coding (in a separate branch)
------------------------------------------
Now you can get to the "lets do some programming bit". Create a new
branch off 'develop', which we call a "feature" branch.

  NOTE:  Never do development work in 'master' or the 'develop'
  branches. This will just cause you unnecessary work, and makes
  my job more difficult fetching code from your repository.

  $> git checkout -b myfeature develop

Now write some code, an make some commits. All the commits will go
into the branch named 'myfeature'. To see a graphical overview of your
repository, type 'gitk --all'


Moving local commits out of a wrong branch
------------------------------------------
Now if you accidentally made commits in 'master' or 'develop', it is
not a problem to fix. This is the huge benefit of Git. Commits are
local at first, so things can be shuffled around before you make them
public.

The easiest way to fix commits in a wrong branch, is to use the GUI
tool 'gitk'. Run 'gitk --all'

Find the commit under the 'develop' branch that still references
'origin/develop', then right-click and select "Create new branch".
Give at a meaningful name. We'll call it 'feature-1' just for now:

Now close gitk, and switch to that new branch.

  git checkout feature-1

Now back into gitk via 'gitk --all'. The 'feature-1' branch will be in
bold, indicating it is the current branch. Now we are going to
cherry-pick commits from another branch. This just means we are going
to duplicate commits from one branch into another.

Find the commit(s) you made in the wrong branch. From oldest to
newest, select a commit, right-click and select "Cherry-pick this
commit". You will now see that commit is duplicated in your
'feature-1' branch. Keep going until you have cherry-picked all your
commits you want to move.

Now you should have all your commits is the right branch, but
'develop' still has them too. No problem. We will simply tell git
discard those commits, by resetting the 'develop' branch to match
'origin/develop'.

Select the commit containing the reference 'origin/develop' (this
should be the same commit you branched your 'feature-1' branch from.
Right click on that commit, and select "Reset develop branch to here".

Now if you refresh the view, F5, or quit and restart gitk, you will
see your local commit history has been fixed, and your local commits
have been moved to the feature branch.


How to share my feature branch
------------------------------
Finally, we want to share the 'myfeature' branch, so we need to push
it to the 'github' remote.

  $> git push github myfeature


This will push the 'myfeature' branch to your repository on Github.
Now on the Github website under the 'myfeature' branch, there should
be a button "send a pull request". Click that, and I'll be notified
via email to take a look at your code.

To keep your repository in sync with the official fpGUI repository,
pull from 'origin' (which will be SourceForge, or my fpGUI mirror on
Github - depending which repository you clone in the beginning). Make
sure you are in say the 'master' branch. Then do the following:

  $> git push github


How to delete a remote branch
-----------------------------
Once you are done with a branch you shared - for example if it was
merged into the official fpGUI code, then you can delete the branch
from your Github repository.

  $> git push github :myfeature


How to delete a local branch
----------------------------
Now the 'myfeature' branch is deleted on the remote repository. Now
you can delete it locally on your PC too. Make sure you our in some
other branch, not 'myfeature'.

eg:  $> git checkout master
     $> git branch -d myfeature



For any details on any of the commands used above, Git includes
excellent help. Just type:

  $> git help <command>

eg:

  $> git help remote
  $> git help branch
  $> git help push



The Github also has some excellent documentation on using Git, and
using the Github services. Here is one such document.

About Remote Repositories:
  https://help.github.com/categories/18/articles
  

  --------------------[ end  ]---------------------