En introduktion
Most images in this presentation are from the Pro Git book. The entire Pro Git book, written by Scott Chacon and Ben Straub and published by Apress, is available here. All content is licensed under the Creative Commons Attribution Non Commercial Share Alike 3.0 license. Print versions of the book are available on Amazon.com.
Some images are from Git With The Program: Introduction to Basic Git Concepts - Drupal Camp LA 2013. All content is licensed under the CC Attribution-ShareAlike License.
In [1]:
from IPython.core.display import HTML
HTML('<iframe width="560" height="315" src="https://www.youtube.com/embed/pOSqctHH9vY" frameborder="0" allowfullscreen></iframe>')
Out[1]:
<img src="snapshots.png", width=600>
<img src="deltas.png", width=600>
<img src="sha1.jpg", width=300>
<img src="areas.png", width=600>
In [2]:
%%bash
cd /tmp
rm -rf TickProject
mkdir TickProject
cd TickProject
git init
tree -aC
In [3]:
%%bash
. quickedit v0.1
# git archive --format=tar --prefix=src/ --remote=~/src/maker-presentation $TAG:TickCounter | tar xf -
tree -aCI .git
git status
In [4]:
%%bash
cd /tmp/TickProject
git add .
git status
In [5]:
%%bash
cd /tmp/TickProject
git commit -a -m "Initial revision"
git status
In [6]:
!. quickedit v0.2
In [7]:
%%bash
cd /tmp/TickProject && rm -rf build
meson src build
In [8]:
%%bash
ninja -C /tmp/TickProject/build
In [9]:
%%bash
cd /tmp/TickProject
git status
Add an .gitignore file There are plenty of examples of .gitignore files on the net and/or use e.g., https://www.gitignore.io
In [10]:
%%bash
cd /tmp/TickProject
git status
<img src="branch-and-history.png", width=600>
In [11]:
%%bash
cd /tmp/TickProject
git branch -v
Creating a New Branch <img src="two-branches.png", width=600>
HEAD pointing to a branch <img src="head-to-master.png", width=600>
Switching Branch <img src="head-to-testing.png", width=600>
The HEAD branch moves forward when a commit is made <img src="advance-testing.png", width=600>
HEAD moves when you checkout <img src="checkout-master.png", width=600>
Git-flow http://nvie.com/posts/a-successful-git-branching-model/ <img src="Git-branching-model.pdf", width=600>
Cactus https://barro.github.io/2016/02/a-succesful-git-branching-model-considered-harmful/ <img src="cactus-model-200.png", width=200>
BBC News http://www.integralist.co.uk/posts/github-workflow.html
Git Pro book https://git-scm.com/book/en/v2/Git-Branching-Branching-Workflows
In [12]:
%%bash
cd /tmp
rm -rf spdlog
rm -rf 3rd/spdlog
git clone https://github.com/gabime/spdlog.git spdlog
In [13]:
%%bash
cd /tmp/spdlog
ls -la
In [14]:
%%bash
cd /tmp/spdlog-build
ls -l
In [15]:
%%bash
cd /tmp/spdlog-build
xcodebuild -configuration Release -target install
Notice the installed .cmake files and spdlog.pc
In [16]:
%%bash
cd /tmp/TickProject
git checkout -b logging
# git branch logging
# git checkout logging
In [17]:
%%bash
. quickci Log4 Log5 Log6
git log
Check differences in SourceTree. Build and run.
In [18]:
%%bash
cd /tmp/TickProject
ninja -C build
In [19]:
%%bash
cd /tmp/TickProject/src
git checkout master
git branch features
In [20]:
%%bash
cd /tmp/TickProject/src
echo This row at the end will prevent TickProject from building >> main.cpp
git diff
git commit -am "This will be a conflict"
Add some features on the features branch
In [21]:
%%bash
cd /tmp/TickProject/src
git checkout features
sed -i 's/Hello World/Hello Makers/g' main.cpp
git diff
git commit -am "Changed greeting"
In [22]:
%%bash
cd /tmp/TickProject/src
echo // This row at the end will compile >> main.cpp
git diff
git commit -am "Added a row at the end of main.cpp"
Merge features onto master --> Conflict
Check always out the branch which shall be modified!
In [26]:
%%bash
cd /tmp/TickProject/src
git checkout master
git merge features
Resolve conlict in SourceTree
Commit merge
In [27]:
%%bash
cd /tmp/TickProject/src
git status
In [28]:
%%bash
cd /tmp/TickProject/src
git commit -am "Features added"
In [29]:
%%bash
cd /tmp/TickProject
git checkout logging
I usually create a tmp branch at this point (If something goes wrong, just remove after)
In [30]:
%%bash
cd /tmp/TickProject
git branch logging-tmp
Use git rebase interactively to squash the logging branch
Use git rebase interactively Let's perform this in SourceTree via a terminal.
Like so: git rebase -i 06558f1d77a09bb41a97bf3eda20e1af3f551a39
After squash
In [31]:
%%bash
cd /tmp/TickProject
git checkout logging
git rebase master
After rebase of logging
Now master can be updated with a fast forward merge of logging
In [32]:
%%bash
cd /tmp/TickProject
git checkout master
git merge logging
Remove logging-tmp
In [33]:
%%bash
cd /tmp/TickProject
git branch -d logging-tmp
In [34]:
%%bash
cd /tmp/TickProject
git branch -D logging-tmp
Reflog to your help if something has gone really wrong
In [35]:
%%bash
cd /tmp/TickProject
git reflog
In [36]:
!. quickedit v0.2
2. Bind
In [40]:
%%bash
cd /tmp/TickProject
git checkout master
git remote add origin https://github.com/topcatse/TickProject.git
git push --set-upstream origin master
3. Clone TickProject from GitHub to a second repository
In [41]:
%%bash
cd /tmp
git clone https://github.com/topcatse/TickProject.git TickProject2
cd TickProject2
tree -aCI .git
In [42]:
%%bash
cd /tmp
ls -l
4. Add some code locally in a new branch 'travis' and push upstream
In [43]:
%%bash
cd /tmp/TickProject
git checkout -b travis
git archive --format=tar --remote=~/src/maker-presentation v0.2 .travis.yml | tar xf -
git add .travis.yml
git commit -am "Added travis-ci build"
git push -u origin travis
5. Fetch from upstream to TickProject2
In [44]:
%%bash
cd /tmp/TickProject2
git fetch origin
git branch -a
In [45]:
%%bash
cd /tmp/TickProject2
# git checkout -b travis --track origin/travis
git checkout travis
6. At GitHub create a pull request to merge travis into master. Acknowledge. Update TickCounter2!
In [46]:
%%bash
cd /tmp/TickProject2
git fetch origin
git branch -a
In [47]:
%%bash
cd /tmp/TickProject2
git checkout master
git log master..origin/master
In [48]:
%%bash
cd /tmp/TickProject2
git merge origin/master
git status