Git | Cookbook

Inhaltsverzeichnis [Anzeigen]

Github hints

Repository — Quick setup

Clone repository

.. or create a new repository on the command line

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
echo "# Init " >> README.md
git init
git add README.md
git commit -m "first commit"
git remote add origin <url>
git push -u origin master
echo "# Init " >> README.md git init git add README.md git commit -m "first commit" git remote add origin <url> git push -u origin master
echo "# Init " >> README.md
git init
git add README.md
git commit -m "first commit"
git remote add origin <url>
git push -u origin master

…or push an existing repository from the command line

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
git remote add origin git@github.com:<username>/<repository>.git
git push -u origin master
git remote add origin git@github.com:<username>/<repository>.git git push -u origin master
git remote add origin git@github.com:<username>/<repository>.git
git push -u origin master

Merge branch with master

Merging via command line

Step 1: From your project repository, bring in the changes and test.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
git fetch origin
git checkout -b develop origin/develop
git merge master
git fetch origin git checkout -b develop origin/develop git merge master
git fetch origin
git checkout -b develop origin/develop
git merge master

Step 2: Merge the changes and update on GitHub.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
git checkout master
git merge --no-ff develop
git push origin master
git checkout master git merge --no-ff develop git push origin master
git checkout master
git merge --no-ff develop
git push origin master

Useful commands

To show information about a remote, for example if tracked branches are up-to-date:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
git remote show origin
git remote -v
git remote add <shortname> <url>
git fetch <remote>
git push <remote> <branch>
git remote show <remote>
git remote rename <old> <new>
git remote remove <name>
git remote show origin git remote -v git remote add <shortname> <url> git fetch <remote> git push <remote> <branch> git remote show <remote> git remote rename <old> <new> git remote remove <name>
git remote show origin
git remote -v
git remote add <shortname> <url>
git fetch <remote>
git push <remote> <branch>
git remote show <remote>
git remote rename <old> <new>
git remote remove <name>

To show log messages of the changes between branches:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
git log origin/master ^master
git log origin/master ^master
git log origin/master ^master

Show log graph

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
git log --pretty=format:"
<h4 class="wp-block-heading" id="to-show-differences-between-branches"><span id="To_show_differences_between_branches">To show differences between branches:</span></h4>
<pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">$ git diff master origin/master</pre><h4 class="wp-block-heading" id="show-what-git-pull-will-doing"><span id="Show_what_git_pull_will_doing">Show , what git pull will doing</span></h4><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">$ git fetch && git diff HEAD..@{u}</pre><p>Or add the command to ~/.gitconfig file:</p><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">[alias]
diffpull=!git fetch && git diff HEAD..@{u}</pre><h4 class="wp-block-heading" id="run-this-to-see-how-git-diff-resolution-works"><span id="Run_this_to_see_how_git_diff_resolution_works">Run this to see how git diff resolution works</span></h4><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">git rev-parse origin</pre><h4 class="wp-block-heading" id="delete-remote-branch"><span id="Delete_remote_branch">Delete remote branch</span></h4><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">git clone <repository> master
cd master
git push origin --delete feature-2.01.03</pre><h4 class="wp-block-heading" id="show-log"><span id="Show_log">Show log</span></h4><pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">git log --oneline --graph --all --decorate</pre><h4 class="wp-block-heading" id="undo-commit"><span id="Undo_commit">Undo commit</span></h4><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">git commit --amend</pre><h4 class="wp-block-heading" id="unstaging-a-staged-file"><span id="Unstaging_a_staged_file">Unstaging a staged file</span></h4><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">git reset HEAD <filename></pre><h4 class="wp-block-heading" id="unmodifying-a-modified-file"><span id="Unmodifying_a_Modified_File">Unmodifying a Modified File</span></h4><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">$ git checkout -- <filename></pre><h4 class="wp-block-heading" id="retrieve-last-modification-date"><span id="Retrieve_last_modification_date">Retrieve last modification date </span></h4><pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">git ls-files -z | xargs -0 -n1 -I{} -- git log -1 --format="
<h2 class="wp-block-heading" id="git-configuration"><span id="Git_Configuration">Git Configuration</span></h2>
<h3 class="wp-block-heading" id="show-location-of-configuration-files"><span id="Show_location_of_configuration_files">Show location of configuration files</span></h3>
<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">git config --list --show-origin</pre><p>This dows not work, if you have set the environment var GIT_CONFIG. In this case, do</p><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">unset GIT_CONFIG
git config --global --list</pre><h2 class="wp-block-heading" id="edit-config-files"><span id="Edit_config_files">Edit config files</span></h2><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">git config --edit --global</pre><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">git config --edit --system</pre><figure class="wp-block-table"><table><thead><tr><th>DESCRIPTION</th><th>GIT COMMAND</th></tr></thead><tbody><tr><td>Configure the author name to be used with your commits.</td><td><code>git config --global user.name "XXX"</code></td></tr><tr><td>Configure the author email address to be used with your commits</td><td><code>git config --global user.email xxx@example.com</code></td></tr><tr><td>Will remove user credential details from the repository</td><td><code>git config --local credential.helper ""</code></td></tr><tr><td></td><td>git config —show-origin</td></tr><tr><td>List all currently configured remote repository URLs</td><td><code>git remote -v</code></td></tr><tr><td>If you haven’t connected your local repository to a remote server, To add a remote server to a local repository</td><td><code>git remote add origin <repo_url></code></td></tr></tbody></table></figure><h2 class="wp-block-heading" id="git-commit-and-push"><span id="Git_Commit_and_Push">Git Commit and Push</span></h2><figure class="wp-block-table"><table><thead><tr><th>DESCRIPTION</th><th>GIT COMMAND</th></tr></thead><tbody><tr><td>Create a file name <code>README.md</code> with <code>Readme content</code> content</td><td><code>echo "Readme content" >> README.md</code></td></tr><tr><td>List the files you’ve changed and those you still need to add or commit</td><td><code>git status</code></td></tr><tr><td>Add all or one file to staging</td><td><code>git add .</code> OR <code>git add file_name</code></td></tr><tr><td>Commit changes to head with message</td><td><code>git commit -m 'message'</code></td></tr><tr><td>Commit any files you’ve added with <code>git add</code>, and also commit any files you’ve changed since then</td><td><code>git commit -a</code></td></tr><tr><td>Send all commits from local repository to remote repository</td><td><code>git push</code></td></tr><tr><td>Do a <code>git push</code> and sets the default remote branch for the current local branch. So any future <code>git pull</code> command will attempt to bring in commits from the <code><remote-branch></code>into the current local branch</td><td><code>git push -u <remote-branch></code></td></tr><tr><td>Send changes to the master branch of your remote repository</td><td><code>git push origin master</code></td></tr><tr><td>Push a specific branch to your remote repository</td><td><code>git push origin <branch_name></code></td></tr><tr><td>Push all branches to your remote repository</td><td><code>git push --all origin</code></td></tr></tbody></table></figure><h2 class="wp-block-heading" id="working-with-the-git-workflow"><span id="Working_with_the_Git_Workflow">Working with the Git Workflow</span></h2><p>The following steps are based on a branching model, described <a href="https://nvie.com/posts/a-successful-git-branching-model/">here</a>.</p><figure class="wp-block-table"><table><tbody><tr><th>Name</th><th> Beschreibung</th></tr><tr><td>master</td><td></td></tr><tr><td>hotfixes</td></tr><tr><td>release</td></tr><tr><td>develop</td></tr><tr><td>feature</td></tr></tbody></table></figure><h3 class="wp-block-heading" id="Workflow-MitBranchesarbeiten"><span id="Working_with_branches">Working with branches</span></h3><h4 class="wp-block-heading" id="Workflow-Brancheserstellen"><span id="Create_branch_8216develop8217">Create branch ‘develop’</span></h4><pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">$ git clone git@github.com:<USER>/<REPO>.git develop
$ cd develop
$ git checkout -b develop
$ git push --set-upstream origin develop</pre><h4 class="wp-block-heading" id="create-branch-feature-xxx"><span id="Create_branch_8216feature-xxx8217">Create branch ‘feature-xxx’</span></h4><p>We dont’t want do clone the whole repository, but only the files needed for the feature</p><pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">$ git clone -b develop -n --depth 1 git@github.com:<USER>/<REPO>.git feature-2.2.0
$ cd feature-2.2.0
</pre><h4 class="wp-block-heading" id="Workflow-Branchlöschen"><span id="Branch_loschen">Branch löschen</span></h4><pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">$ git push origin -delete hotfix-1.2.1-compress-data</pre><h3 class="wp-block-heading" id="Workflow-Workflow-Cheatsheet"><span id="Workflow_8211_Cheatsheet">Workflow – Cheatsheet</span></h3><h4 class="wp-block-heading" id="working-with-branches"><span id="Working_with_branches-2">Working with branches</span></h4><p><strong>How to rename git local and remote branches</strong></p><div class="wp-block-columns has-2-columns is-layout-flex wp-container-core-columns-is-layout-3 wp-block-columns-is-layout-flex"><div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow"><p>Check out branch with old name</p></div><div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow"><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">git checkout feature-2.1.2</pre></div></div><div class="wp-block-columns has-2-columns is-layout-flex wp-container-core-columns-is-layout-4 wp-block-columns-is-layout-flex"><div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow"><p>Rename branch</p></div><div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow"><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">git branch -m feature-2.01.02</pre></div></div><div class="wp-block-columns has-2-columns is-layout-flex wp-container-core-columns-is-layout-5 wp-block-columns-is-layout-flex"><div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow"><p>Checkin branch with new name</p></div><div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow"><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">git push origin :feature-2.1.2 feature-2.01.02</pre></div></div><p><strong>1. Rename your local branch.</strong></p><p>If you have named a branch incorrectly AND pushed this to the remote repository follow these steps before any other developers get a chance to jump on you and give you shit for not correctly following naming conventions.</p><p>If you are on the branch you want to rename:</p><pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">git branch -m new-name</pre><p>If you are on a different branch:</p><pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">git branch -m old-name new-name</pre><p><strong>2. Delete the old-name remote branch and push the new-name local branch.</strong></p><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">git push origin :old-name new-name</pre><p><strong>3. Reset the upstream branch for the new-name local branch.</strong>Switch to the branch and then:</p><pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">git push origin -u new-name</pre><p>Or you as a fast way to do that, you can use these 3 steps: command in your terminal</p><pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">git branch -m old_branch new_branch # Rename branch locally
git push origin :old_branch # Delete old branch
git push --set-upstream origin new_branch # Push new branch, set local branch to track new remote</pre><figure class="wp-block-table"><table><tbody><tr><th>Neues Feature erstellen</th></tr><tr><td>Repository clonen</td><td>gitcheckoutbfeature1.2.2develop</td></tr><tr><td>Änderungendurchführen</td></tr><tr><td>Änderungeneinchecken</td><td> git checkout develop<br>gitmergenofffeature1.2.2<br> git branch -d feature-1.2.2 <br>gitpushorigindevelop</td></tr><tr></tr></tbody></table></figure><figureclass="wpblocktable"><table><tbody><tr><th>NeuenHotfixerstelllen</th></tr><tr><td>Repositoryauschecken</td><td> git checkout -b hotfix-1.2.1 master</td></tr><tr><td>Änderungen durchführen</td></tr><tr><td>Änderungen einchecken</td><td>gitcommitamhotfix:hotfix1.2.1|compressmart</td></tr><tr><td>Hotfixbeenden</td><td> git checkout master<br>gitmergenoffhotfix1.2.1<br> git tag -a 1.2.1</td></tr><tr><td>Hotfix in Master einchecken</td><td>gitcheckoutdevelop<br> git merge –no-ff hotfix-1.2.1 </td></tr><tr><td>Hotfix Branch entfernen</td><td>gitbranchdhotfix1.2.1</td></tr><tr></tr></tbody></table></figure><figureclass="wpblocktable"><table><tbody><tr><th>NeuesReleaseerstellen:</th></tr><tr><td>Repositoryclonen</td><td> git checkout -b release-1.2 develop</td></tr><tr><td>Änderungen durchführen</td></tr><tr><td>Änderungen einchecken</td><td>gitcommitamrelease:changesforrelease1.2</td></tr><tr><td>Releasebeenden</td><td> git checkout master<br>gitmergenoffrelease1.2<br> git tag -a 1.2</td></tr></tbody></table></figure><h2 class="wp-block-heading" id="git-flow"><span id="Git_Flow">Git Flow</span></h2><h4 class="wp-block-heading" id="initialize"><span id="Initialize">Initialize</span></h4><p>Start using git-flow by initializing it inside an existing git repository:</p><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">git flow init</pre><h4 class="wp-block-heading" id="start-a-new-feature"><span id="Start_a_new_feature">Start a new feature</span></h4><p>Development of new features starting from the ‘develop’ branch.</p><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">git flow feature start MYFEATURE</pre><h4 class="wp-block-heading" id="finish-up-a-feature"><span id="Finish_up_a_feature">Finish up a feature</span></h4><p>Finish the development of a feature. This action performs the following</p><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">git flow feature finish MYFEATURE</pre><h4 class="wp-block-heading" id="publish-a-feature"><span id="Publish_a_feature">Publish a feature</span></h4><p>Publish a feature to the remote server so it can be used by other users.</p><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">git flow feature publish MYFEATURE</pre><h3 class="wp-block-heading" id="getting-a-published-feature"><span id="Getting_a_published_feature">Getting a published feature</span></h3><p>Get a feature published by another user.</p><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">git flow feature pull origin MYFEATURE</pre><p>You can track a feature on origin by using</p><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">git flow feature track MYFEATURE</pre><h4 class="wp-block-heading" id="start-a-release"><span id="Start_a_release">Start a release</span></h4><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">git flow release start RELEASE [BASE]</pre><p>It’s wise to publish the release branch after creating it to allow release commits by other developers. Do it similar to feature publishing with the command:</p><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">git flow release publish RELEASE</pre><p>(You can track a remote release with the <br><code>git flow release track RELEASE</code>command)</p><h4 class="wp-block-heading" id="finish-up-a-release"><span id="Finish_up_a_release">Finish up a release</span></h4><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">git flow release finish RELEASE</pre><p>Don’t forget to push your tags with <code>git push origin --tags</code></p><h4 class="wp-block-heading" id="hotfixes"><span id="Hotfixes">Hotfixes</span></h4><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">git flow hotfix start VERSION [BASENAME]</pre><h4 class="wp-block-heading" id="finish-a-hotfix"><span id="Finish_a_hotfix">Finish a hotfix</span></h4><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">git flow hotfix finish VERSION</pre><h2 class="wp-block-heading" id="usefull-commands"><span id="Usefull_commands">Usefull commands</span></h2><figure class="wp-block-table"><table><tbody><tr><th>basic commands</th><th>description</th></tr><tr><td>git init</td></tr><tr><td>git status  [ -s ]</td><td>status of files and local repo</td></tr><tr><td>git ls-files</td><td>show files which are tracked by git</td></tr><tr><td>git log [ –oneline ]<br>git log [–oneline –graph –decorate –all]</td><td>shows commit history</td></tr><tr><td>git add <changed file><br>git add .git add -u</td><td>add single file to indexadd all files from the workspace to indexstage current workspace into index to cleanup inconsistencies</td></tr><tr><td>git commit [ -m ‘message’ ]</td><td>commit into local repo only</td></tr><tr><td>git push -u origin master</td><td>push the repo from local to remote repo</td></tr><tr><td>git help [option]</td><td>get help page for specific options</td></tr><tr><td>git config –global alias.bla “command”<br>git bla [– <filename>]</td><td>set alias bla to a specific commandexec alias (for specific file)</td></tr><tr><td>git mv fileA fileB<br>git commit -m “…..”</td><td>rename fileA to fileBand commit</td></tr><tr><td>git rm fileC<br>git commit -m “…..”</td><td>delete fileCand commit</td></tr><tr></tr><tr><th>advanced commands</th><th>description</th></tr><tr><td>git reset HEAD <filename></td><td>undo changes from index back to workspace</td></tr><tr><td>git checkout <filename><br>git checkout master<br>git checkout <branchname></td><td>checkout single file from local repo to workspacecheckout/switch to the master branchcheckout/switch to another branch</td></tr><tr><td>git checkout -b <new branchname><br>git branch <new branchname></td><td>create new branch and switch to it immediatelycreate new branch in the background, doesn’t switch to it</td></tr><tr><td>git branch</td><td>shows all available branches</td></tr><tr><td>git diff<br>git difftool</td><td>show differences of local and committed file<br>shows diff in vimdiff</td></tr><tr><td>git merge <other branch><br>git mergetool</td><td>merge other branch into master (current branch)manage the different files in vimdiff</td></tr><tr><td>git branch -d <branchname></td><td>delete branch (does NOT include merge)</td></tr><tr><td>git branch -m <new name></td><td>rename a</td></tr><tr><td> git diff master..development</td><td>compare two branches</td></tr><tr><td>git tag <mytag><br>git tag -a v1.0 -m “description”<br>git show v1.0</td><td>add an additional label/tag to a branchannotation tag with release informationshows details of tag v1.0</td></tr><tr><td>git stash</td></tr><tr><td>git reset <ID> [–soft | –mixed | –hard]<br>git reflog ….</td></tr><tr><td>git fetch ….</td><td>update local repo with changes from remote repo. (non destructive)</td></tr><tr><td>git pull …</td><td>update local repo with changes from remote repo. it does effectively a fetch and merge in one command</td></tr><tr><td>git clone https://<<em>username</em>>:<<em>token</em>>@github.com/<<em>organisation-space</em>>/<<em>repository</em>><br></td><td>download the remote repo into local workspace</td></tr><tr><td>git remote -v<br>git remote show origin</td><td>shows url of remote reposhows detail infos of a remote repo</td></tr><tr></tr><tr><td>.gitignore</td><td>contains filename to exclude from git</td></tr></tbody></table></figure><h2 class="wp-block-heading" id="git-workflow"><span id="Git_Workflow">Git Workflow</span></h2><h3 class="wp-block-heading" id="release"><span id="Release">Release</span></h3><h4 class="wp-block-heading" id="creating-a-release-branch"><span id="Creating_a_release_branch">Creating a release branch</span></h4><div class="wp-block-columns has-2-columns is-layout-flex wp-container-core-columns-is-layout-6 wp-block-columns-is-layout-flex"><div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow"><p> Release branches are created from the <code>develop</code> branch. For example, say version 1.1.5 is the current production release and we have a big release coming up. The state of <code>develop</code>is ready for the “next release” and we have decided that this will become version 1.2 (rather than 1.1.6 or 2.0). So we branch off and give the release branch a name reflecting the new version number:</p></div><div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow"><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">gitcheckoutbrelease1.2develop</pre></div></div><divclass="wpblockcolumnshas2columnsislayoutflexwpcontainercorecolumnsislayout7wpblockcolumnsislayoutflex"><divclass="wpblockcolumnislayoutflowwpblockcolumnislayoutflow"><p>Aftercreatinganewbranchandswitchingtoit,webumptheversionnumber.Here,<code>bumpversion.sh</code>isafictionalshellscriptthatchangessomefilesintheworkingcopytoreflectthenewversion.(Thiscanofcoursebeamanualchangethepointbeingthat<em>some</em>fileschange.)Then,thebumpedversionnumberiscommitted.</p><p>Thisnewbranchmayexistthereforawhile,untilthereleasemayberolledoutdefinitely.Duringthattime,bugfixesmaybeappliedinthisbranch(ratherthanonthe<code>develop</code>branch).Addinglargenewfeatureshereisstrictlyprohibited.Theymustbemergedinto<code>develop</code>,andtherefore,waitforthenextbigrelease.</p></div><divclass="wpblockcolumnislayoutflowwpblockcolumnislayoutflow"><preclass="EnlighterJSRAW"dataenlighterlanguage="generic"dataenlightertheme=""dataenlighterhighlight=""dataenlighterlinenumbers=""dataenlighterlineoffset=""dataenlightertitle=""dataenlightergroup=""> ./bump-version.sh 1.2<br>
$ git commit -a -m "Version 1.2"</pre></div></div><h4 class="wp-block-heading" id="finishing-a-release-branch"><span id="Finishing_a_release_branchnbsp"> Finishing a release branch </span></h4><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">$ git checkout master
$ git merge --no-ff release-1.2
$ git tag -a 1.2
$ git checkout develop
$ git merge --no-ff release-1.2
$ git branch -d release-1.2</pre><div class="wp-block-columns has-2-columns is-layout-flex wp-container-core-columns-is-layout-8 wp-block-columns-is-layout-flex"><div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow"><p>When the state of the release branch is ready to become a real release, some actions need to be carried out.</p><p>First, the release branch is merged into <code>master</code> (since every commit on <code>master</code> is a new release <em>by definition</em>, remember).</p><p>Next, that commit on <code>master</code> must be tagged for easy future reference to this historical version.</p><p>Finally, the changes made on the release branch need to be merged back into <code>develop</code>, so that future releases also contain these bug fixes.</p></div><div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow"><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">$ git checkout master
$ git merge --no-ff release-1.2
$ git tag -a 1.2</pre></div></div><div class="wp-block-columns has-2-columns is-layout-flex wp-container-core-columns-is-layout-9 wp-block-columns-is-layout-flex"><div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow"><p>The release is now done, and tagged for future reference.</p><p>To keep the changes made in the release branch, we need to merge those back into <code>develop</code>, though. In Git:</p></div><div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow"><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">$ git checkout develop
$ git merge --no-ff release-1.2</pre></div></div><div class="wp-block-columns has-2-columns is-layout-flex wp-container-core-columns-is-layout-10 wp-block-columns-is-layout-flex"><div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow"><p>This step may well lead to a merge conflict (probably even, since we have changed the version number). If so, fix it and commit.</p><p>Now we are really done and the release branch may be removed, since we don’t need it anymore:</p></div><div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow"><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">$ git branch -d release-1.2</pre></div></div><h3 class="wp-block-heading" id="feature"><span id="Feature">Feature</span></h3><figure class="wp-block-image"><img decoding="async" src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%201%201'%3E%3C/svg%3E" data-src="http://blog.via-internet.de/wp-content/uploads/2019/03/fb@2x-e1554287024987-700x261.png" alt="" class="wp-image-4387 lazy"></figure><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">$ git checkout -b myfeature develop
$ .. do changes...
$ git checkout develop
$ git merge --no-ff myfeature
$ git branch -d myfeature
$ git push origin develop</pre><div class="wp-block-columns has-2-columns is-layout-flex wp-container-core-columns-is-layout-11 wp-block-columns-is-layout-flex"><div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow"><h4 class="wp-block-heading" id="creating-a-feature-branch"><span id="Creating_a_feature_branchnbsp">Creating a feature branch </span></h4><p>When starting work on a new feature, branch off from the <code>develop</code> branch.</p><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">$ git checkout -b myfeature develop
Switched to a new branch "myfeature"
</pre><h4 class="wp-block-heading" id="incorporating-a-finished-feature-on-develop"><span id="Incorporating_a_finished_feature_on_developnbsp">Incorporating a finished feature on develop </span></h4><p>Finished features may be merged into the <code>develop</code> branch to definitely add them to the upcoming release:</p><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">$ git checkout develop<
$ git merge --no-ff myfeature
$ git branch -d myfeature
$ git push origin develop </pre></div><div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow"></div></div><div class="wp-block-columns has-2-columns is-layout-flex wp-container-core-columns-is-layout-12 wp-block-columns-is-layout-flex"><div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow"><p> The <code>--no-ff</code> flag causes the merge to always create a new commit object, even if the merge could be performed with a fast-forward. This avoids losing information about the historical existence of a feature branch and groups together all commits that together added the feature.</p><p>In the latter case, it is impossible to see from the Git history which of the commit objects together have implemented a feature—you would have to manually read all the log messages. Reverting a whole feature (i.e. a group of commits), is a true headache in the latter situation, whereas it is easily done if the <code>--no-ff</code> flag was used.</p></div><div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow"><figure class="wp-block-image"><img class="lazy" decoding="async" src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%201%201'%3E%3C/svg%3E" data-src="https://nvie.com/img/merge-without-ff@2x.png" alt=""></figure></div></div><h2 class="wp-block-heading" id="hotfix"><span id="Hotfix">Hotfix</span></h2><figure class="wp-block-image"><img decoding="async" src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%201%201'%3E%3C/svg%3E" data-src="http://blog.via-internet.de/wp-content/uploads/2019/03/hotfix-branches@2x-e1554287153961-700x519.png" alt="" class="wp-image-4394 lazy"></figure><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">$ git checkout -b hotfix-1.2.1 master
$ ... do changes ...
$ git commit -a -m "Hotfix Version 1.2.1"
$ .. fix bug
$ git commit -m "Fixed severe production problem"
$ git checkout master
$ git merge --no-ff hotfix-1.2.1
$ git tag -a 1.2.1
# incude hotfix into develop
$ git checkout develop
$ git merge --no-ff hotfix-1.2.1
# finally, remove hotfix branch
$ git branch -d hotfix-1.2.1</pre><h2 class="wp-block-heading" id="troubleshooting"><span id="Troubleshooting">Troubleshooting</span></h2><h4 class="wp-block-heading" id="debugging-github-errors"><span id="Debugging_Github_Errors">Debugging Github Errors</span></h4><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">export GIT_TRACE_PACKET=1
export GIT_TRACE=1
export GIT_CURL_VERBOSE=1</pre><h4 class="wp-block-heading" id="error-message-your-local-changes-to-the-following-files-would-be-overwritten-by-merge"><span id="Error_Message_Your_local_changes_to_the_following_files_would_be_overwritten_by_merge">Error Message: Your local changes to the following files would be overwritten by merge: </span></h4><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">error: Your local changes to the following files would be overwritten by merge:<br>
README.md<br>
Please commit your changes or stash them before you merge.</pre><h4 class="wp-block-heading" id="solution"><span id="Solution">Solution:</span></h4><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">$ git fetch origin master
$ git diff origin/master -- [local-path]</pre><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">$ git add [local-path]
$ gt commit -m "change: in file [local-path]"</pre><h4 class="wp-block-heading" id="fatal-sha1-file-stdout-write-error-broken-pipe"><span id="fatal_sha1_file_8216ltstdoutgt8217_write_error_Broken_Pipe">fatal: sha1 file ‘<stdout>’ write error: Broken Pipe </span></h4><p>When using ssh to connect to the repositoriy, sometime, you got a timeout if you push to many files or if the files are to big</p><h4 class="wp-block-heading" id="one-possible-solution"><span id="One_possible_Solution">One possible Solution</span></h4><p>Configure ssh to use the following value</p><pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">~/.ssh/config</pre><pre class="EnlighterJSRAW" data-enlighter-language="ini" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">Host *
ServerAliveInterval 30
ServerAliveCountMax 4</pre><h4 class="wp-block-heading" id="git-clone-file-name-to-long-on-windows"><span id="git_clone_file_name_to_long_on_windows">git clone: file name to long on windows</span></h4><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">git config --system core.longpaths true</pre><h4 class="wp-block-heading" id="git-config-global-user-email-some-email-com-throws-error-only-one-config-file-at-a-time"><span id="git_config_8211global_useremail_someemailcom_throws_error_only_one_config_file_at_a_time">git config –global user.email “some@email.com” throws “error: only one config file at a time.</span></h4><p>Try to unset GIT_CONFIG and then list your global config with</p><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">unset GIT_CONFIG
git config --global --list</pre><p>Other Links</p><p><a href="https://medium.com/flawless-app-stories/useful-git-commands-for-everyday-use-e1a4de64037d">Useful Git commands for everyday use</a></p><p><a href="https://medium.com/android-bits/10-useful-git-commands-you-always-need-b0d0a50b81e6">10 useful Git commands you always need</a></p><p><a href="https://orga.cat/posts/most-useful-git-commands">Most useful Git commands</a></p><p><a href="https://artandlogic.com/2014/01/git-cheat-sheet/">Git Cheat Sheet</a></p><p><a href="https://dzone.com/articles/useful-git-commands">Useful Git commands</a></p><h2 class="wp-block-heading" id="using-local-filesystem-as-respository-master"><span id="Using_local_Filesystem_as_Respository-Master">Using local Filesystem as Respository-Master</span></h2><h4 class="wp-block-heading" id="preparation"><span id="Preparation">Preparation</span></h4><p>Set environment variables for easy typing</p><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">REPOS=HOME/repos</pre><h4 class="wp-block-heading" id="create-repository"><span id="Create_Repository">Create Repository</span></h4><pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">mkdirREPOS
$ cd $REPOS</pre><pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">$ git init --bare src</pre><h4 class="wp-block-heading" id="create-src-folder"><span id="Create_src_folder">Create src folder</span></h4><pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">mkdirHOME/entw
$ cd $HOME/entw
$ mkdir src
$ cd src
$ git init</pre><h4 class="wp-block-heading" id="create-some-content"><span id="Create_some_content">Create some content</span></h4><pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">$ touch README.md</pre><pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">$ git add -A</pre><pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">$ git commit -m "initial commit"</pre><pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">gitremoteaddoriginREPOS/src
$ git remote -v
$ git push --set-upstream origin master
$ git push origin master</pre><h4 class="wp-block-heading" id="create-clone"><span id="Create_clone">Create clone</span></h4><pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">mkdirHOME/test
$ cd $HOME/test</pre><pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">gitcloneHOME/repos/src</pre><pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">$ cd src
$ ls -al
total 0
drwxr-xr-x 4 user wheel 128 19 Mär 18:48 .
drwxr-xr-x 3 user wheel 96 19 Mär 18:48 ..
drwxr-xr-x 12 user wheel 384 19 Mär 18:48 .git
-rw-r--r-- 1 user wheel 0 19 Mär 18:48 README.md</pre><p>You will notice, that the file README.md is empty. Because it was ony created with touch.</p><h4 class="wp-block-heading" id="add-some-content-to-source-repository"><span id="Add_some_content_to_source_repository">Add some content to source repository</span></h4><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">cdHOME/entw/src
$ echo "# This is the README.md from ENTW" >README.md
$ touch git_update
$ touch git_push</pre><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">$ ls -al
total 16
drwxr-xr-x 6 user wheel 192 19 Mär 18:53 .
drwxr-xr-x 3 user wheel 96 19 Mär 18:43 ..
drwxr-xr-x 12 user wheel 384 19 Mär 18:47 .git
-rw-r--r-- 1 user wheel 34 19 Mär 18:52 README.md
-rw-r--r-- 1 user wheel 0 19 Mär 18:53 git_push
-rw-r--r-- 1 user wheel 0 19 Mär 18:53 git_update</pre><h4 class="wp-block-heading" id="add-changes-to-repository"><span id="Add_changes_to_repository">Add changes to repository</span></h4><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">$ git add -A
$ git commit -m "-"
[master 106b27a] -
3 files changed, 1 insertion(+)
create mode 100644 git_push
create mode 100644 git_update</pre><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">$ git push --set-upstream origin master
Objekte aufzählen: 5, Fertig.
Zähle Objekte: 100
Delta-Kompression verwendet bis zu 8 Threads.
Komprimiere Objekte: 100
Schreibe Objekte: 100
Gesamt 3 (Delta 0), Wiederverwendet 0 (Delta 0)
To ..../repos/src
7ed6d3b..106b27a master -> master
Branch 'master' folgt nun Remote-Branch 'master' von 'origin'.</pre><h4 class="wp-block-heading" id="update-clone"><span id="Update_clone">Update clone</span></h4><pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">cdOME/test/src
$ git pull
# git fetch # This updates 'remote' portion of local repo.
# git reset --hard origin/<your-working-branch>
remote: Objekte aufzählen: 5, Fertig.
remote: Zähle Objekte: 100
remote: Komprimiere Objekte: 100
remote: Gesamt 3 (Delta 0), Wiederverwendet 0 (Delta 0)
Entpacke Objekte: 100
Von .../repos/src
7ed6d3b..106b27a master -> origin/master</pre><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">$ git merge origin/master
Aktualisiere 7ed6d3b..106b27a
Fast-forward
README.md | 1 +
git_push | 0
git_update | 0
3 files changed, 1 insertion(+)
create mode 100644 git_push
create mode 100644 git_update</pre><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">$ ls -al
total 16
drwxr-xr-x 6 user wheel 192 19 Mär 19:02 .
drwxr-xr-x 3 user wheel 96 19 Mär 18:48 ..
drwxr-xr-x 14 user wheel 448 19 Mär 19:02 .git
-rw-r--r-- 1 user wheel 34 19 Mär 19:02 README.md
-rw-r--r-- 1 user wheel 0 19 Mär 19:02 git_push
-rw-r--r-- 1 user wheel 0 19 Mär 19:02 git_update</pre><h2 class="wp-block-heading" id="todo"><span id="TODO">TODO</span></h2><h4 class="wp-block-heading" id="see-changes-before-pulling-from-remote-git-repositoryf"><span id="See_changes_before_pulling_from_remote_git_repositoryf">See changes before pulling from remote git repository<a href="https://gist.github.com/jtdp/5443297#file-gistfile1-sh"><strong>f</strong></a></span></h4><figure class="wp-block-table"><table><tbody><tr><td># fetch the changes from the remote</td></tr><tr><td>git fetch origin</td></tr><tr></tr><tr><td># show commit logs of changes</td></tr><tr><td>git log master..origin/master</td></tr><tr></tr><tr><td># show diffs of changes</td></tr><tr><td>git diff master..origin/master</td></tr><tr></tr><tr><td># apply the changes by merge..</td></tr><tr><td>git merge origin/master</td></tr><tr></tr><tr><td># .. or just pull the changes</td></tr><tr><td>git pull</td></tr></tbody></table></figure><h4 class="wp-block-heading" id="you-want-to-push-your-local-files-to-remote-files"><span id="You_want_to_push_your_local_files_to_remote_files">You want to push your local files to remote files</span></h4><pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">git push -f <remote> <branch></pre><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">git push -f origin master</pre><h3 class="wp-block-heading" id="configure-hooks"><span id="Configure_Hooks">Configure Hooks</span></h3><pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">git config --global core.hooksPath .githooks
mkdir .githooks
cp .git/hooks/* .githooks</pre><h4 class="wp-block-heading" id="prepare-commit"><span id="commit-msg">commit-msg</span></h4><pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">#!/bin/sh
#
NAME=$(git rev-parse --abbrev-ref HEAD)
DESCRIPTION=(gitconfigbranch."NAME".description)
echo "NAME":(cat "1")>"1"
if [ -n "$DESCRIPTION" ]
then
echo "" >> "$1"
echo DESCRIPTION>>"1"
fi</pre><h4 class="wp-block-heading" id="prepare-commit"><span id="prepare-commit">prepare-commit</span></h4><pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">#!/bin/sh
#
COMMIT_MSG_FILE=$1
COMMIT_SOURCE=$2
SHA1=$3
branchPath=$(git symbolic-ref -q HEAD)
branchName=${branchPath##*/}
if [ -n "$branchName" ]; then
echo "branchName|(cat $1)" > $1
fi</pre><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">file=$(git config hooks.versionfilename)
if [[ -z $file ]]
then
file=".version"
fi
# Version number
echo "(gitrevparseabbrevrefHEAD):(git describe --tags --long)" >$file
exec git add $file</pre><h4 class="wp-block-heading" id="pre-commit"><span id="pre-commit">pre-commit</span></h4><pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">#!/bin/sh
_BRANCHPATH=$(git symbolic-ref -q HEAD)
_BRANCHNAME=${_BRANCHPATH##*/}
_TIMESTAMP="$(date '+
echo "HOOK : $0"
echo "PARAMETER : '$*''"
echo "BRANCHPATH: $_BRANCHPATH"
echo "BRANCHNAME: $_BRANCHNAME"
LOG() {
[[ "GIT_COMMIT_DETAILED_LOGGING" == "YES" ]] && echo "LOG:*"
}
REPLACE()
{
local _TYP; _TYP="$1"; shift
local _TAG; _TAG="$1"; shift
local _WITH; _WITH="$1"; shift
local _FILE; _FILE="$1"; shift
case "$_TYP" in
PYTHON) perl -pi -e 's/(\s*)(__DEPLOY_'${_TAG}'\s*=\s*)(".+")/${1}${2}"'"${_WITH}"'"/' "${_FILE}"
;;
*) LOG "Undefined typ '$TYP' for file $_FILE"
;;
esac
rm -f "${_FILE}.bak"
}
LOG "working on branch $_BRANCH"
for _FILE in $(git diff-index --name-status --cached HEAD | grep -v ^D | cut -c3-)
do
LOG "checking: $_FILE"
# Only examine known text files
if [[ "$_FILE" =~ [.](py)$ ]]; then
LOG "patching: $_FILE"
REPLACE PYTHON TAG "$_BRANCHNAME" "$_FILE"
REPLACE PYTHON TIMESTAMP "$_TIMESTAMP" "$_FILE"
fi
done
</pre><h2 class="wp-block-heading" id="get-information"><span id="Get_Information">Get Information</span></h2><figure class="wp-block-table"><table><tbody><tr><td>git rev-parse –abbrev-ref HEAD</td><td>get branch name</td><td>feature/add-new-content</td></tr><tr><td>git symbolic-ref -q HEAD</td><td></td><td>refs/heads/<meta charset="utf-8">feature/add-new-content</td></tr><tr><td><meta charset="utf-8">git rev-parse –show-toplevel</td><td><meta charset="utf-8">show current path of git repository</td><td></td></tr><tr><td></td><td></td><td></td></tr><tr><td></td><td></td><td></td></tr></tbody></table></figure><h2 class="wp-block-heading" id="config"><span id="Config">Config</span></h2><h3 class="wp-block-heading" id="change-github-repository-for-local-clone"><span id="Change_Github_repository_for_local_clone">Change Github repository for local clone</span></h3><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">cd <original repository>
git remote set-url origin https://github.com/<new git user>/<new project name>
git push -u origin master
</pre><h3 class="wp-block-heading" id="cr-lf-mapping"><span id="CRLF_Mapping">CR/LF Mapping</span></h3><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">git config core.autocrlf true
git config --global core.safecrlf false</pre><h2 class="wp-block-heading" id="create-release"><span id="Create_Release">Create Release</span></h2><pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">#!/bin/bash
if [ $# -ne 1 ]; then
echo "Syntax: release [VERSION]"
exit 1
fi
VERSION=$1
# Create release
git flow release start $VERSION || exit 1
GIT_MERGE_AUTOEDIT=no git flow release finish -m VERSIONVERSION
# Publish release
git push origin HEAD --tags
# Merge release into develop
git checkout develop
git merge master</pre></pre>
git log --pretty=format:" <h4 class="wp-block-heading" id="to-show-differences-between-branches"><span id="To_show_differences_between_branches">To show differences between branches:</span></h4> <pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">gitdiffmasterorigin/master</pre><h4class="wpblockheading"id="showwhatgitpullwilldoing"><spanid="Showwhatgitpullwilldoing">Show,whatgitpullwilldoing</span></h4><preclass="EnlighterJSRAW"dataenlighterlanguage="generic"dataenlightertheme=""dataenlighterhighlight=""dataenlighterlinenumbers=""dataenlighterlineoffset=""dataenlightertitle=""dataenlightergroup=""> git fetch && git diff HEAD..@{u}</pre><p>Or add the command to ~/.gitconfig file:</p><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">[alias] diffpull=!git fetch && git diff HEAD..@{u}</pre><h4 class="wp-block-heading" id="run-this-to-see-how-git-diff-resolution-works"><span id="Run_this_to_see_how_git_diff_resolution_works">Run this to see how git diff resolution works</span></h4><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">git rev-parse origin</pre><h4 class="wp-block-heading" id="delete-remote-branch"><span id="Delete_remote_branch">Delete remote branch</span></h4><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">git clone <repository> master cd master git push origin --delete feature-2.01.03</pre><h4 class="wp-block-heading" id="show-log"><span id="Show_log">Show log</span></h4><pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">git log --oneline --graph --all --decorate</pre><h4 class="wp-block-heading" id="undo-commit"><span id="Undo_commit">Undo commit</span></h4><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">git commit --amend</pre><h4 class="wp-block-heading" id="unstaging-a-staged-file"><span id="Unstaging_a_staged_file">Unstaging a staged file</span></h4><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">git reset HEAD <filename></pre><h4 class="wp-block-heading" id="unmodifying-a-modified-file"><span id="Unmodifying_a_Modified_File">Unmodifying a Modified File</span></h4><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">gitcheckout<filename></pre><h4class="wpblockheading"id="retrievelastmodificationdate"><spanid="Retrievelastmodificationdate">Retrievelastmodificationdate</span></h4><preclass="EnlighterJSRAW"dataenlighterlanguage="shell"dataenlightertheme=""dataenlighterhighlight=""dataenlighterlinenumbers="false"dataenlighterlineoffset=""dataenlightertitle=""dataenlightergroup="">gitlsfilesz|xargs0n1Igitlog1format="<h2class="wpblockheading"id="gitconfiguration"><spanid="GitConfiguration">GitConfiguration</span></h2><h3class="wpblockheading"id="showlocationofconfigurationfiles"><spanid="Showlocationofconfigurationfiles">Showlocationofconfigurationfiles</span></h3><preclass="EnlighterJSRAW"dataenlighterlanguage="generic"dataenlightertheme=""dataenlighterhighlight=""dataenlighterlinenumbers=""dataenlighterlineoffset=""dataenlightertitle=""dataenlightergroup="">gitconfiglistshoworigin</pre><p>Thisdowsnotwork,ifyouhavesettheenvironmentvarGITCONFIG.Inthiscase,do</p><preclass="EnlighterJSRAW"dataenlighterlanguage="generic"dataenlightertheme=""dataenlighterhighlight=""dataenlighterlinenumbers=""dataenlighterlineoffset=""dataenlightertitle=""dataenlightergroup="">unsetGITCONFIGgitconfiggloballist</pre><h2class="wpblockheading"id="editconfigfiles"><spanid="Editconfigfiles">Editconfigfiles</span></h2><preclass="EnlighterJSRAW"dataenlighterlanguage="generic"dataenlightertheme=""dataenlighterhighlight=""dataenlighterlinenumbers=""dataenlighterlineoffset=""dataenlightertitle=""dataenlightergroup="">gitconfigeditglobal</pre><preclass="EnlighterJSRAW"dataenlighterlanguage="generic"dataenlightertheme=""dataenlighterhighlight=""dataenlighterlinenumbers=""dataenlighterlineoffset=""dataenlightertitle=""dataenlightergroup="">gitconfigeditsystem</pre><figureclass="wpblocktable"><table><thead><tr><th>DESCRIPTION</th><th>GITCOMMAND</th></tr></thead><tbody><tr><td>Configuretheauthornametobeusedwithyourcommits.</td><td><code>gitconfigglobaluser.name"XXX"</code></td></tr><tr><td>Configuretheauthoremailaddresstobeusedwithyourcommits</td><td><code>gitconfigglobaluser.emailxxx@example.com</code></td></tr><tr><td>Willremoveusercredentialdetailsfromtherepository</td><td><code>gitconfiglocalcredential.helper""</code></td></tr><tr><td></td><td>gitconfigshoworigin</td></tr><tr><td>ListallcurrentlyconfiguredremoterepositoryURLs</td><td><code>gitremotev</code></td></tr><tr><td>Ifyouhaventconnectedyourlocalrepositorytoaremoteserver,Toaddaremoteservertoalocalrepository</td><td><code>gitremoteaddorigin<repourl></code></td></tr></tbody></table></figure><h2class="wpblockheading"id="gitcommitandpush"><spanid="GitCommitandPush">GitCommitandPush</span></h2><figureclass="wpblocktable"><table><thead><tr><th>DESCRIPTION</th><th>GITCOMMAND</th></tr></thead><tbody><tr><td>Createafilename<code>README.md</code>with<code>Readmecontent</code>content</td><td><code>echo"Readmecontent">>README.md</code></td></tr><tr><td>Listthefilesyouvechangedandthoseyoustillneedtoaddorcommit</td><td><code>gitstatus</code></td></tr><tr><td>Addalloronefiletostaging</td><td><code>gitadd.</code>OR<code>gitaddfilename</code></td></tr><tr><td>Commitchangestoheadwithmessage</td><td><code>gitcommitmmessage</code></td></tr><tr><td>Commitanyfilesyouveaddedwith<code>gitadd</code>,andalsocommitanyfilesyouvechangedsincethen</td><td><code>gitcommita</code></td></tr><tr><td>Sendallcommitsfromlocalrepositorytoremoterepository</td><td><code>gitpush</code></td></tr><tr><td>Doa<code>gitpush</code>andsetsthedefaultremotebranchforthecurrentlocalbranch.Soanyfuture<code>gitpull</code>commandwillattempttobringincommitsfromthe<code><remotebranch></code>intothecurrentlocalbranch</td><td><code>gitpushu<remotebranch></code></td></tr><tr><td>Sendchangestothemasterbranchofyourremoterepository</td><td><code>gitpushoriginmaster</code></td></tr><tr><td>Pushaspecificbranchtoyourremoterepository</td><td><code>gitpushorigin<branchname></code></td></tr><tr><td>Pushallbranchestoyourremoterepository</td><td><code>gitpushallorigin</code></td></tr></tbody></table></figure><h2class="wpblockheading"id="workingwiththegitworkflow"><spanid="WorkingwiththeGitWorkflow">WorkingwiththeGitWorkflow</span></h2><p>Thefollowingstepsarebasedonabranchingmodel,described<ahref="https://nvie.com/posts/asuccessfulgitbranchingmodel/">here</a>.</p><figureclass="wpblocktable"><table><tbody><tr><th>Name</th><th>Beschreibung</th></tr><tr><td>master</td><td></td></tr><tr><td>hotfixes</td></tr><tr><td>release</td></tr><tr><td>develop</td></tr><tr><td>feature</td></tr></tbody></table></figure><h3class="wpblockheading"id="WorkflowMitBranchesarbeiten"><spanid="Workingwithbranches">Workingwithbranches</span></h3><h4class="wpblockheading"id="WorkflowBrancheserstellen"><spanid="Createbranch8216develop8217">Createbranchdevelop</span></h4><preclass="EnlighterJSRAW"dataenlighterlanguage="shell"dataenlightertheme=""dataenlighterhighlight=""dataenlighterlinenumbers=""dataenlighterlineoffset=""dataenlightertitle=""dataenlightergroup=""> git clone git@github.com:<USER>/<REPO>.git develop cddevelop git checkout -b develop gitpushsetupstreamorigindevelop</pre><h4class="wpblockheading"id="createbranchfeaturexxx"><spanid="Createbranch8216featurexxx8217">Createbranchfeaturexxx</span></h4><p>Wedonttwantdoclonethewholerepository,butonlythefilesneededforthefeature</p><preclass="EnlighterJSRAW"dataenlighterlanguage="shell"dataenlightertheme=""dataenlighterhighlight=""dataenlighterlinenumbers=""dataenlighterlineoffset=""dataenlightertitle=""dataenlightergroup=""> git clone -b develop -n --depth 1 git@github.com:<USER>/<REPO>.git feature-2.2.0 cdfeature2.2.0</pre><h4class="wpblockheading"id="WorkflowBranchlöschen"><spanid="Branchloschen">Branchlöschen</span></h4><preclass="EnlighterJSRAW"dataenlighterlanguage="shell"dataenlightertheme=""dataenlighterhighlight=""dataenlighterlinenumbers=""dataenlighterlineoffset=""dataenlightertitle=""dataenlightergroup=""> git push origin -delete hotfix-1.2.1-compress-data</pre><h3 class="wp-block-heading" id="Workflow-Workflow-Cheatsheet"><span id="Workflow_8211_Cheatsheet">Workflow – Cheatsheet</span></h3><h4 class="wp-block-heading" id="working-with-branches"><span id="Working_with_branches-2">Working with branches</span></h4><p><strong>How to rename git local and remote branches</strong></p><div class="wp-block-columns has-2-columns is-layout-flex wp-container-core-columns-is-layout-3 wp-block-columns-is-layout-flex"><div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow"><p>Check out branch with old name</p></div><div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow"><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">git checkout feature-2.1.2</pre></div></div><div class="wp-block-columns has-2-columns is-layout-flex wp-container-core-columns-is-layout-4 wp-block-columns-is-layout-flex"><div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow"><p>Rename branch</p></div><div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow"><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">git branch -m feature-2.01.02</pre></div></div><div class="wp-block-columns has-2-columns is-layout-flex wp-container-core-columns-is-layout-5 wp-block-columns-is-layout-flex"><div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow"><p>Checkin branch with new name</p></div><div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow"><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">git push origin :feature-2.1.2 feature-2.01.02</pre></div></div><p><strong>1. Rename your local branch.</strong></p><p>If you have named a branch incorrectly AND pushed this to the remote repository follow these steps before any other developers get a chance to jump on you and give you shit for not correctly following naming conventions.</p><p>If you are on the branch you want to rename:</p><pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">git branch -m new-name</pre><p>If you are on a different branch:</p><pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">git branch -m old-name new-name</pre><p><strong>2. Delete the old-name remote branch and push the new-name local branch.</strong></p><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">git push origin :old-name new-name</pre><p><strong>3. Reset the upstream branch for the new-name local branch.</strong>Switch to the branch and then:</p><pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">git push origin -u new-name</pre><p>Or you as a fast way to do that, you can use these 3 steps: command in your terminal</p><pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">git branch -m old_branch new_branch # Rename branch locally git push origin :old_branch # Delete old branch git push --set-upstream origin new_branch # Push new branch, set local branch to track new remote</pre><figure class="wp-block-table"><table><tbody><tr><th>Neues Feature erstellen</th></tr><tr><td>Repository clonen</td><td>gitcheckoutbfeature1.2.2develop</td></tr><tr><td>Änderungendurchführen</td></tr><tr><td>Änderungeneinchecken</td><td> git checkout develop<br>gitmergenofffeature1.2.2<br> git branch -d feature-1.2.2 <br>gitpushorigindevelop</td></tr><tr></tr></tbody></table></figure><figureclass="wpblocktable"><table><tbody><tr><th>NeuenHotfixerstelllen</th></tr><tr><td>Repositoryauschecken</td><td> git checkout -b hotfix-1.2.1 master</td></tr><tr><td>Änderungen durchführen</td></tr><tr><td>Änderungen einchecken</td><td>gitcommitamhotfix:hotfix1.2.1|compressmart</td></tr><tr><td>Hotfixbeenden</td><td> git checkout master<br>gitmergenoffhotfix1.2.1<br> git tag -a 1.2.1</td></tr><tr><td>Hotfix in Master einchecken</td><td>gitcheckoutdevelop<br> git merge –no-ff hotfix-1.2.1 </td></tr><tr><td>Hotfix Branch entfernen</td><td>gitbranchdhotfix1.2.1</td></tr><tr></tr></tbody></table></figure><figureclass="wpblocktable"><table><tbody><tr><th>NeuesReleaseerstellen:</th></tr><tr><td>Repositoryclonen</td><td> git checkout -b release-1.2 develop</td></tr><tr><td>Änderungen durchführen</td></tr><tr><td>Änderungen einchecken</td><td>gitcommitamrelease:changesforrelease1.2</td></tr><tr><td>Releasebeenden</td><td> git checkout master<br>gitmergenoffrelease1.2<br> git tag -a 1.2</td></tr></tbody></table></figure><h2 class="wp-block-heading" id="git-flow"><span id="Git_Flow">Git Flow</span></h2><h4 class="wp-block-heading" id="initialize"><span id="Initialize">Initialize</span></h4><p>Start using git-flow by initializing it inside an existing git repository:</p><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">git flow init</pre><h4 class="wp-block-heading" id="start-a-new-feature"><span id="Start_a_new_feature">Start a new feature</span></h4><p>Development of new features starting from the ‘develop’ branch.</p><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">git flow feature start MYFEATURE</pre><h4 class="wp-block-heading" id="finish-up-a-feature"><span id="Finish_up_a_feature">Finish up a feature</span></h4><p>Finish the development of a feature. This action performs the following</p><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">git flow feature finish MYFEATURE</pre><h4 class="wp-block-heading" id="publish-a-feature"><span id="Publish_a_feature">Publish a feature</span></h4><p>Publish a feature to the remote server so it can be used by other users.</p><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">git flow feature publish MYFEATURE</pre><h3 class="wp-block-heading" id="getting-a-published-feature"><span id="Getting_a_published_feature">Getting a published feature</span></h3><p>Get a feature published by another user.</p><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">git flow feature pull origin MYFEATURE</pre><p>You can track a feature on origin by using</p><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">git flow feature track MYFEATURE</pre><h4 class="wp-block-heading" id="start-a-release"><span id="Start_a_release">Start a release</span></h4><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">git flow release start RELEASE [BASE]</pre><p>It’s wise to publish the release branch after creating it to allow release commits by other developers. Do it similar to feature publishing with the command:</p><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">git flow release publish RELEASE</pre><p>(You can track a remote release with the <br><code>git flow release track RELEASE</code>command)</p><h4 class="wp-block-heading" id="finish-up-a-release"><span id="Finish_up_a_release">Finish up a release</span></h4><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">git flow release finish RELEASE</pre><p>Don’t forget to push your tags with <code>git push origin --tags</code></p><h4 class="wp-block-heading" id="hotfixes"><span id="Hotfixes">Hotfixes</span></h4><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">git flow hotfix start VERSION [BASENAME]</pre><h4 class="wp-block-heading" id="finish-a-hotfix"><span id="Finish_a_hotfix">Finish a hotfix</span></h4><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">git flow hotfix finish VERSION</pre><h2 class="wp-block-heading" id="usefull-commands"><span id="Usefull_commands">Usefull commands</span></h2><figure class="wp-block-table"><table><tbody><tr><th>basic commands</th><th>description</th></tr><tr><td>git init</td></tr><tr><td>git status  [ -s ]</td><td>status of files and local repo</td></tr><tr><td>git ls-files</td><td>show files which are tracked by git</td></tr><tr><td>git log [ –oneline ]<br>git log [–oneline –graph –decorate –all]</td><td>shows commit history</td></tr><tr><td>git add <changed file><br>git add .git add -u</td><td>add single file to indexadd all files from the workspace to indexstage current workspace into index to cleanup inconsistencies</td></tr><tr><td>git commit [ -m ‘message’ ]</td><td>commit into local repo only</td></tr><tr><td>git push -u origin master</td><td>push the repo from local to remote repo</td></tr><tr><td>git help [option]</td><td>get help page for specific options</td></tr><tr><td>git config –global alias.bla “command”<br>git bla [– <filename>]</td><td>set alias bla to a specific commandexec alias (for specific file)</td></tr><tr><td>git mv fileA fileB<br>git commit -m “…..”</td><td>rename fileA to fileBand commit</td></tr><tr><td>git rm fileC<br>git commit -m “…..”</td><td>delete fileCand commit</td></tr><tr></tr><tr><th>advanced commands</th><th>description</th></tr><tr><td>git reset HEAD <filename></td><td>undo changes from index back to workspace</td></tr><tr><td>git checkout <filename><br>git checkout master<br>git checkout <branchname></td><td>checkout single file from local repo to workspacecheckout/switch to the master branchcheckout/switch to another branch</td></tr><tr><td>git checkout -b <new branchname><br>git branch <new branchname></td><td>create new branch and switch to it immediatelycreate new branch in the background, doesn’t switch to it</td></tr><tr><td>git branch</td><td>shows all available branches</td></tr><tr><td>git diff<br>git difftool</td><td>show differences of local and committed file<br>shows diff in vimdiff</td></tr><tr><td>git merge <other branch><br>git mergetool</td><td>merge other branch into master (current branch)manage the different files in vimdiff</td></tr><tr><td>git branch -d <branchname></td><td>delete branch (does NOT include merge)</td></tr><tr><td>git branch -m <new name></td><td>rename a</td></tr><tr><td> git diff master..development</td><td>compare two branches</td></tr><tr><td>git tag <mytag><br>git tag -a v1.0 -m “description”<br>git show v1.0</td><td>add an additional label/tag to a branchannotation tag with release informationshows details of tag v1.0</td></tr><tr><td>git stash</td></tr><tr><td>git reset <ID> [–soft | –mixed | –hard]<br>git reflog ….</td></tr><tr><td>git fetch ….</td><td>update local repo with changes from remote repo. (non destructive)</td></tr><tr><td>git pull …</td><td>update local repo with changes from remote repo. it does effectively a fetch and merge in one command</td></tr><tr><td>git clone https://<<em>username</em>>:<<em>token</em>>@github.com/<<em>organisation-space</em>>/<<em>repository</em>><br></td><td>download the remote repo into local workspace</td></tr><tr><td>git remote -v<br>git remote show origin</td><td>shows url of remote reposhows detail infos of a remote repo</td></tr><tr></tr><tr><td>.gitignore</td><td>contains filename to exclude from git</td></tr></tbody></table></figure><h2 class="wp-block-heading" id="git-workflow"><span id="Git_Workflow">Git Workflow</span></h2><h3 class="wp-block-heading" id="release"><span id="Release">Release</span></h3><h4 class="wp-block-heading" id="creating-a-release-branch"><span id="Creating_a_release_branch">Creating a release branch</span></h4><div class="wp-block-columns has-2-columns is-layout-flex wp-container-core-columns-is-layout-6 wp-block-columns-is-layout-flex"><div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow"><p> Release branches are created from the <code>develop</code> branch. For example, say version 1.1.5 is the current production release and we have a big release coming up. The state of <code>develop</code>is ready for the “next release” and we have decided that this will become version 1.2 (rather than 1.1.6 or 2.0). So we branch off and give the release branch a name reflecting the new version number:</p></div><div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow"><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">gitcheckoutbrelease1.2develop</pre></div></div><divclass="wpblockcolumnshas2columnsislayoutflexwpcontainercorecolumnsislayout7wpblockcolumnsislayoutflex"><divclass="wpblockcolumnislayoutflowwpblockcolumnislayoutflow"><p>Aftercreatinganewbranchandswitchingtoit,webumptheversionnumber.Here,<code>bumpversion.sh</code>isafictionalshellscriptthatchangessomefilesintheworkingcopytoreflectthenewversion.(Thiscanofcoursebeamanualchangethepointbeingthat<em>some</em>fileschange.)Then,thebumpedversionnumberiscommitted.</p><p>Thisnewbranchmayexistthereforawhile,untilthereleasemayberolledoutdefinitely.Duringthattime,bugfixesmaybeappliedinthisbranch(ratherthanonthe<code>develop</code>branch).Addinglargenewfeatureshereisstrictlyprohibited.Theymustbemergedinto<code>develop</code>,andtherefore,waitforthenextbigrelease.</p></div><divclass="wpblockcolumnislayoutflowwpblockcolumnislayoutflow"><preclass="EnlighterJSRAW"dataenlighterlanguage="generic"dataenlightertheme=""dataenlighterhighlight=""dataenlighterlinenumbers=""dataenlighterlineoffset=""dataenlightertitle=""dataenlightergroup=""> ./bump-version.sh 1.2<br> git commit -a -m "Version 1.2"</pre></div></div><h4 class="wp-block-heading" id="finishing-a-release-branch"><span id="Finishing_a_release_branchnbsp"> Finishing a release branch  </span></h4><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group=""> git checkout master gitmergenoffrelease1.2 git tag -a 1.2 gitcheckoutdevelop git merge --no-ff release-1.2 gitbranchdrelease1.2</pre><divclass="wpblockcolumnshas2columnsislayoutflexwpcontainercorecolumnsislayout8wpblockcolumnsislayoutflex"><divclass="wpblockcolumnislayoutflowwpblockcolumnislayoutflow"><p>Whenthestateofthereleasebranchisreadytobecomearealrelease,someactionsneedtobecarriedout.</p><p>First,thereleasebranchismergedinto<code>master</code>(sinceeverycommiton<code>master</code>isanewrelease<em>bydefinition</em>,remember).</p><p>Next,thatcommiton<code>master</code>mustbetaggedforeasyfuturereferencetothishistoricalversion.</p><p>Finally,thechangesmadeonthereleasebranchneedtobemergedbackinto<code>develop</code>,sothatfuturereleasesalsocontainthesebugfixes.</p></div><divclass="wpblockcolumnislayoutflowwpblockcolumnislayoutflow"><preclass="EnlighterJSRAW"dataenlighterlanguage="generic"dataenlightertheme=""dataenlighterhighlight=""dataenlighterlinenumbers=""dataenlighterlineoffset=""dataenlightertitle=""dataenlightergroup=""> git checkout master gitmergenoffrelease1.2 git tag -a 1.2</pre></div></div><div class="wp-block-columns has-2-columns is-layout-flex wp-container-core-columns-is-layout-9 wp-block-columns-is-layout-flex"><div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow"><p>The release is now done, and tagged for future reference.</p><p>To keep the changes made in the release branch, we need to merge those back into <code>develop</code>, though. In Git:</p></div><div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow"><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">gitcheckoutdevelop git merge --no-ff release-1.2</pre></div></div><div class="wp-block-columns has-2-columns is-layout-flex wp-container-core-columns-is-layout-10 wp-block-columns-is-layout-flex"><div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow"><p>This step may well lead to a merge conflict (probably even, since we have changed the version number). If so, fix it and commit.</p><p>Now we are really done and the release branch may be removed, since we don’t need it anymore:</p></div><div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow"><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">gitbranchdrelease1.2</pre></div></div><h3class="wpblockheading"id="feature"><spanid="Feature">Feature</span></h3><figureclass="wpblockimage"><imgdecoding="async"src="data:image/svg+xml, git checkout -b myfeature develop ..dochanges... git checkout develop gitmergenoffmyfeature git branch -d myfeature git push origin develop</pre><div class="wp-block-columns has-2-columns is-layout-flex wp-container-core-columns-is-layout-11 wp-block-columns-is-layout-flex"><div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow"><h4 class="wp-block-heading" id="creating-a-feature-branch"><span id="Creating_a_feature_branchnbsp">Creating a feature branch </span></h4><p>When starting work on a new feature, branch off from the <code>develop</code> branch.</p><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group=""> git checkout -b myfeature develop Switched to a new branch "myfeature" </pre><h4 class="wp-block-heading" id="incorporating-a-finished-feature-on-develop"><span id="Incorporating_a_finished_feature_on_developnbsp">Incorporating a finished feature on develop </span></h4><p>Finished features may be merged into the <code>develop</code> branch to definitely add them to the upcoming release:</p><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">gitcheckoutdevelop< git merge --no-ff myfeature gitbranchdmyfeature git push origin develop </pre></div><div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow"></div></div><div class="wp-block-columns has-2-columns is-layout-flex wp-container-core-columns-is-layout-12 wp-block-columns-is-layout-flex"><div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow"><p> The <code>--no-ff</code> flag causes the merge to always create a new commit object, even if the merge could be performed with a fast-forward. This avoids losing information about the historical existence of a feature branch and groups together all commits that together added the feature.</p><p>In the latter case, it is impossible to see from the Git history which of the commit objects together have implemented a feature—you would have to manually read all the log messages. Reverting a whole feature (i.e. a group of commits), is a true headache in the latter situation, whereas it is easily done if the <code>--no-ff</code> flag was used.</p></div><div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow"><figure class="wp-block-image"><img class="lazy" decoding="async" src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%201%201'%3E%3C/svg%3E" data-src="https://nvie.com/img/merge-without-ff@2x.png" alt=""></figure></div></div><h2 class="wp-block-heading" id="hotfix"><span id="Hotfix">Hotfix</span></h2><figure class="wp-block-image"><img decoding="async" src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%201%201'%3E%3C/svg%3E" data-src="http://blog.via-internet.de/wp-content/uploads/2019/03/hotfix-branches@2x-e1554287153961-700x519.png" alt="" class="wp-image-4394 lazy"></figure><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">gitcheckoutbhotfix1.2.1master ... do changes ... gitcommitam"HotfixVersion1.2.1" .. fix bug gitcommitm"Fixedsevereproductionproblem" git checkout master gitmergenoffhotfix1.2.1 git tag -a 1.2.1 # incude hotfix into develop gitcheckoutdevelop git merge --no-ff hotfix-1.2.1 # finally, remove hotfix branch gitbranchdhotfix1.2.1</pre><h2class="wpblockheading"id="troubleshooting"><spanid="Troubleshooting">Troubleshooting</span></h2><h4class="wpblockheading"id="debugginggithuberrors"><spanid="DebuggingGithubErrors">DebuggingGithubErrors</span></h4><preclass="EnlighterJSRAW"dataenlighterlanguage="generic"dataenlightertheme=""dataenlighterhighlight=""dataenlighterlinenumbers=""dataenlighterlineoffset=""dataenlightertitle=""dataenlightergroup="">exportGITTRACEPACKET=1exportGITTRACE=1exportGITCURLVERBOSE=1</pre><h4class="wpblockheading"id="errormessageyourlocalchangestothefollowingfileswouldbeoverwrittenbymerge"><spanid="ErrorMessageYourlocalchangestothefollowingfileswouldbeoverwrittenbymerge">ErrorMessage:Yourlocalchangestothefollowingfileswouldbeoverwrittenbymerge:</span></h4><preclass="EnlighterJSRAW"dataenlighterlanguage="generic"dataenlightertheme=""dataenlighterhighlight=""dataenlighterlinenumbers=""dataenlighterlineoffset=""dataenlightertitle=""dataenlightergroup="">error:Yourlocalchangestothefollowingfileswouldbeoverwrittenbymerge:<br>README.md<br>Pleasecommityourchangesorstashthembeforeyoumerge.</pre><h4class="wpblockheading"id="solution"><spanid="Solution">Solution:</span></h4><preclass="EnlighterJSRAW"dataenlighterlanguage="generic"dataenlightertheme=""dataenlighterhighlight=""dataenlighterlinenumbers=""dataenlighterlineoffset=""dataenlightertitle=""dataenlightergroup=""> git fetch origin master gitdifforigin/master[localpath]</pre><preclass="EnlighterJSRAW"dataenlighterlanguage="generic"dataenlightertheme=""dataenlighterhighlight=""dataenlighterlinenumbers=""dataenlighterlineoffset=""dataenlightertitle=""dataenlightergroup=""> git add [local-path] gt commit -m "change: in file [local-path]"</pre><h4 class="wp-block-heading" id="fatal-sha1-file-stdout-write-error-broken-pipe"><span id="fatal_sha1_file_8216ltstdoutgt8217_write_error_Broken_Pipe">fatal: sha1 file ‘<stdout>’ write error: Broken Pipe </span></h4><p>When using ssh to connect to the repositoriy, sometime, you got a timeout if you push to many files or if the files are to big</p><h4 class="wp-block-heading" id="one-possible-solution"><span id="One_possible_Solution">One possible Solution</span></h4><p>Configure ssh to use the following value</p><pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">~/.ssh/config</pre><pre class="EnlighterJSRAW" data-enlighter-language="ini" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">Host *
     ServerAliveInterval 30
     ServerAliveCountMax 4</pre><h4 class="wp-block-heading" id="git-clone-file-name-to-long-on-windows"><span id="git_clone_file_name_to_long_on_windows">git clone: file name to long on windows</span></h4><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">git config --system core.longpaths true</pre><h4 class="wp-block-heading" id="git-config-global-user-email-some-email-com-throws-error-only-one-config-file-at-a-time"><span id="git_config_8211global_useremail_someemailcom_throws_error_only_one_config_file_at_a_time">git config –global user.email “some@email.com” throws “error: only one config file at a time.</span></h4><p>Try to unset GIT_CONFIG and then list your global config with</p><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">unset GIT_CONFIG
git config --global --list</pre><p>Other Links</p><p><a href="https://medium.com/flawless-app-stories/useful-git-commands-for-everyday-use-e1a4de64037d">Useful Git commands for everyday use</a></p><p><a href="https://medium.com/android-bits/10-useful-git-commands-you-always-need-b0d0a50b81e6">10 useful Git commands you always need</a></p><p><a href="https://orga.cat/posts/most-useful-git-commands">Most useful Git commands</a></p><p><a href="https://artandlogic.com/2014/01/git-cheat-sheet/">Git Cheat Sheet</a></p><p><a href="https://dzone.com/articles/useful-git-commands">Useful Git commands</a></p><h2 class="wp-block-heading" id="using-local-filesystem-as-respository-master"><span id="Using_local_Filesystem_as_Respository-Master">Using local Filesystem as Respository-Master</span></h2><h4 class="wp-block-heading" id="preparation"><span id="Preparation">Preparation</span></h4><p>Set environment variables for easy typing</p><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">
REPOS=HOME/repos</pre><h4 class="wp-block-heading" id="create-repository"><span id="Create_Repository">Create Repository</span></h4><pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group=""> mkdir REPOS cd REPOS</pre><pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group=""> git init --bare src</pre><h4 class="wp-block-heading" id="create-src-folder"><span id="Create_src_folder">Create src folder</span></h4><pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group=""> mkdir HOME/entw cd HOME/entw mkdir src cd src git init</pre><h4 class="wp-block-heading" id="create-some-content"><span id="Create_some_content">Create some content</span></h4><pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group=""> touch README.md</pre><pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group=""> git add -A</pre><pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group=""> git commit -m "initial commit"</pre><pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group=""> git remote add origin REPOS/src git remote -v git push --set-upstream origin master git push origin master</pre><h4 class="wp-block-heading" id="create-clone"><span id="Create_clone">Create clone</span></h4><pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group=""> mkdir HOME/test cd HOME/test</pre><pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group=""> git clone HOME/repos/src</pre><pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group=""> cd src ls -al total 0 drwxr-xr-x 4 user wheel 128 19 Mär 18:48 . drwxr-xr-x 3 user wheel 96 19 Mär 18:48 .. drwxr-xr-x 12 user wheel 384 19 Mär 18:48 .git -rw-r--r-- 1 user wheel 0 19 Mär 18:48 README.md</pre><p>You will notice, that the file README.md is empty. Because it was ony created with touch.</p><h4 class="wp-block-heading" id="add-some-content-to-source-repository"><span id="Add_some_content_to_source_repository">Add some content to source repository</span></h4><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group=""> cd HOME/entw/src echo "# This is the README.md from ENTW" >README.md touch git_update touch git_push</pre><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group=""> ls -al total 16 drwxr-xr-x 6 user wheel 192 19 Mär 18:53 . drwxr-xr-x 3 user wheel 96 19 Mär 18:43 .. drwxr-xr-x 12 user wheel 384 19 Mär 18:47 .git -rw-r--r-- 1 user wheel 34 19 Mär 18:52 README.md -rw-r--r-- 1 user wheel 0 19 Mär 18:53 git_push -rw-r--r-- 1 user wheel 0 19 Mär 18:53 git_update</pre><h4 class="wp-block-heading" id="add-changes-to-repository"><span id="Add_changes_to_repository">Add changes to repository</span></h4><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group=""> git add -A git commit -m "-" [master 106b27a] - 3 files changed, 1 insertion(+) create mode 100644 git_push create mode 100644 git_update</pre><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group=""> git push --set-upstream origin master Objekte aufzählen: 5, Fertig. Zähle Objekte: 100 Delta-Kompression verwendet bis zu 8 Threads. Komprimiere Objekte: 100 Schreibe Objekte: 100 Gesamt 3 (Delta 0), Wiederverwendet 0 (Delta 0) To ..../repos/src 7ed6d3b..106b27a master -> master Branch 'master' folgt nun Remote-Branch 'master' von 'origin'.</pre><h4 class="wp-block-heading" id="update-clone"><span id="Update_clone">Update clone</span></h4><pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group=""> cd OME/test/src git pull # git fetch # This updates 'remote' portion of local repo. # git reset --hard origin/<your-working-branch> remote: Objekte aufzählen: 5, Fertig. remote: Zähle Objekte: 100 remote: Komprimiere Objekte: 100 remote: Gesamt 3 (Delta 0), Wiederverwendet 0 (Delta 0) Entpacke Objekte: 100 Von .../repos/src 7ed6d3b..106b27a master -> origin/master</pre><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group=""> git merge origin/master Aktualisiere 7ed6d3b..106b27a Fast-forward README.md | 1 + git_push | 0 git_update | 0 3 files changed, 1 insertion(+) create mode 100644 git_push create mode 100644 git_update</pre><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group=""> ls -al total 16 drwxr-xr-x 6 user wheel 192 19 Mär 19:02 . drwxr-xr-x 3 user wheel 96 19 Mär 18:48 .. drwxr-xr-x 14 user wheel 448 19 Mär 19:02 .git -rw-r--r-- 1 user wheel 34 19 Mär 19:02 README.md -rw-r--r-- 1 user wheel 0 19 Mär 19:02 git_push -rw-r--r-- 1 user wheel 0 19 Mär 19:02 git_update</pre><h2 class="wp-block-heading" id="todo"><span id="TODO">TODO</span></h2><h4 class="wp-block-heading" id="see-changes-before-pulling-from-remote-git-repositoryf"><span id="See_changes_before_pulling_from_remote_git_repositoryf">See changes before pulling from remote git repository<a href="https://gist.github.com/jtdp/5443297#file-gistfile1-sh"><strong>f</strong></a></span></h4><figure class="wp-block-table"><table><tbody><tr><td># fetch the changes from the remote</td></tr><tr><td>git fetch origin</td></tr><tr></tr><tr><td># show commit logs of changes</td></tr><tr><td>git log master..origin/master</td></tr><tr></tr><tr><td># show diffs of changes</td></tr><tr><td>git diff master..origin/master</td></tr><tr></tr><tr><td># apply the changes by merge..</td></tr><tr><td>git merge origin/master</td></tr><tr></tr><tr><td># .. or just pull the changes</td></tr><tr><td>git pull</td></tr></tbody></table></figure><h4 class="wp-block-heading" id="you-want-to-push-your-local-files-to-remote-files"><span id="You_want_to_push_your_local_files_to_remote_files">You want to push your local files to remote files</span></h4><pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">git push -f <remote> <branch></pre><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">git push -f origin master</pre><h3 class="wp-block-heading" id="configure-hooks"><span id="Configure_Hooks">Configure Hooks</span></h3><pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">git config --global core.hooksPath .githooks mkdir .githooks cp .git/hooks/* .githooks</pre><h4 class="wp-block-heading" id="prepare-commit"><span id="commit-msg">commit-msg</span></h4><pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">#!/bin/sh # NAME=(git rev-parse --abbrev-ref HEAD) DESCRIPTION=(git config branch."NAME".description) echo "NAME"': '(cat "1") > "1" if [ -n "DESCRIPTION" ] then echo "" >> "1" echo DESCRIPTION >> "1" fi</pre><h4 class="wp-block-heading" id="prepare-commit"><span id="prepare-commit">prepare-commit</span></h4><pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">#!/bin/sh # COMMIT_MSG_FILE=1 COMMIT_SOURCE=2 SHA1=3 branchPath=(git symbolic-ref -q HEAD) branchName={branchPath##*/} if [ -n "branchName" ]; then echo "branchName | (cat 1)" > 1 fi</pre><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">file=(git config hooks.versionfilename) if [[ -z file ]] then file=".version" fi # Version number echo "(git rev-parse --abbrev-ref HEAD): (git describe --tags --long)" >file exec git add file</pre><h4 class="wp-block-heading" id="pre-commit"><span id="pre-commit">pre-commit</span></h4><pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">#!/bin/sh _BRANCHPATH=(git symbolic-ref -q HEAD) _BRANCHNAME={_BRANCHPATH##*/} _TIMESTAMP="(date '+ echo "HOOK : 0" echo "PARAMETER : '*''" echo "BRANCHPATH: _BRANCHPATH" echo "BRANCHNAME: _BRANCHNAME" LOG() { [[ "$GIT_COMMIT_DETAILED_LOGGING" == "YES" ]] && echo "LOG: $*" } REPLACE() { local _TYP; _TYP="$1"; shift local _TAG; _TAG="$1"; shift local _WITH; _WITH="$1"; shift local _FILE; _FILE="$1"; shift case "$_TYP" in PYTHON) perl -pi -e 's/(\s*)(__DEPLOY_'${_TAG}'\s*=\s*)(".+")/${1}${2}"'"${_WITH}"'"/' "${_FILE}" ;; *) LOG "Undefined typ '$TYP' for file $_FILE" ;; esac rm -f "${_FILE}.bak" } LOG "working on branch _BRANCH" for _FILE in (git diff-index --name-status --cached HEAD | grep -v ^D | cut -c3-) do LOG "checking: _FILE" # Only examine known text files if [[ "_FILE" =~ [.](py) ]]; then LOG "patching: _FILE" REPLACE PYTHON TAG "_BRANCHNAME" "_FILE" REPLACE PYTHON TIMESTAMP "_TIMESTAMP" "_FILE" fi done </pre><h2 class="wp-block-heading" id="get-information"><span id="Get_Information">Get Information</span></h2><figure class="wp-block-table"><table><tbody><tr><td>git rev-parse –abbrev-ref HEAD</td><td>get branch name</td><td>feature/add-new-content</td></tr><tr><td>git symbolic-ref -q HEAD</td><td></td><td>refs/heads/<meta charset="utf-8">feature/add-new-content</td></tr><tr><td><meta charset="utf-8">git rev-parse –show-toplevel</td><td><meta charset="utf-8">show current path of git repository</td><td></td></tr><tr><td></td><td></td><td></td></tr><tr><td></td><td></td><td></td></tr></tbody></table></figure><h2 class="wp-block-heading" id="config"><span id="Config">Config</span></h2><h3 class="wp-block-heading" id="change-github-repository-for-local-clone"><span id="Change_Github_repository_for_local_clone">Change Github repository for local clone</span></h3><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">cd <original repository> git remote set-url origin https://github.com/<new git user>/<new project name> git push -u origin master </pre><h3 class="wp-block-heading" id="cr-lf-mapping"><span id="CRLF_Mapping">CR/LF Mapping</span></h3><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">git config core.autocrlf true git config --global core.safecrlf false</pre><h2 class="wp-block-heading" id="create-release"><span id="Create_Release">Create Release</span></h2><pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">#!/bin/bash if [ # -ne 1 ]; then echo "Syntax: release [VERSION]" exit 1 fi VERSION=1 # Create release git flow release start VERSION || exit 1 GIT_MERGE_AUTOEDIT=no git flow release finish -m VERSION VERSION # Publish release git push origin HEAD --tags # Merge release into develop git checkout develop git merge master</pre></pre>
git log --pretty=format:"



To show differences between branches:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
$ git diff master origin/master
$ git diff master origin/master
$ git diff master origin/master

Show , what git pull will doing

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
$ git fetch && git diff HEAD..@{u}
$ git fetch && git diff HEAD..@{u}
$ git fetch && git diff HEAD..@{u}

Or add the command to ~/.gitconfig file:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
[alias]
diffpull=!git fetch && git diff HEAD..@{u}
[alias] diffpull=!git fetch && git diff HEAD..@{u}
[alias]
        diffpull=!git fetch && git diff HEAD..@{u}

Run this to see how git diff resolution works

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
git rev-parse origin
git rev-parse origin
git rev-parse origin

Delete remote branch

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
git clone <repository> master
cd master
git push origin --delete feature-2.01.03
git clone <repository> master cd master git push origin --delete feature-2.01.03
git clone <repository> master
cd master
git push origin --delete feature-2.01.03

Show log

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
git log --oneline --graph --all --decorate
git log --oneline --graph --all --decorate
git log --oneline --graph --all --decorate

Undo commit

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
git commit --amend
git commit --amend
git commit --amend

Unstaging a staged file

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
git reset HEAD <filename>
git reset HEAD <filename>
git reset HEAD <filename>

Unmodifying a Modified File

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
$ git checkout -- <filename>
$ git checkout -- <filename>
$ git checkout -- <filename>

Retrieve last modification date

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
git ls-files -z | xargs -0 -n1 -I{} -- git log -1 --format="
<h2 class="wp-block-heading" id="git-configuration"><span id="Git_Configuration">Git Configuration</span></h2>
<h3 class="wp-block-heading" id="show-location-of-configuration-files"><span id="Show_location_of_configuration_files">Show location of configuration files</span></h3>
<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">git config --list --show-origin</pre><p>This dows not work, if you have set the environment var GIT_CONFIG. In this case, do</p><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">unset GIT_CONFIG
git config --global --list</pre><h2 class="wp-block-heading" id="edit-config-files"><span id="Edit_config_files">Edit config files</span></h2><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">git config --edit --global</pre><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">git config --edit --system</pre><figure class="wp-block-table"><table><thead><tr><th>DESCRIPTION</th><th>GIT COMMAND</th></tr></thead><tbody><tr><td>Configure the author name to be used with your commits.</td><td><code>git config --global user.name "XXX"</code></td></tr><tr><td>Configure the author email address to be used with your commits</td><td><code>git config --global user.email xxx@example.com</code></td></tr><tr><td>Will remove user credential details from the repository</td><td><code>git config --local credential.helper ""</code></td></tr><tr><td></td><td>git config —show-origin</td></tr><tr><td>List all currently configured remote repository URLs</td><td><code>git remote -v</code></td></tr><tr><td>If you haven’t connected your local repository to a remote server, To add a remote server to a local repository</td><td><code>git remote add origin <repo_url></code></td></tr></tbody></table></figure><h2 class="wp-block-heading" id="git-commit-and-push"><span id="Git_Commit_and_Push">Git Commit and Push</span></h2><figure class="wp-block-table"><table><thead><tr><th>DESCRIPTION</th><th>GIT COMMAND</th></tr></thead><tbody><tr><td>Create a file name <code>README.md</code> with <code>Readme content</code> content</td><td><code>echo "Readme content" >> README.md</code></td></tr><tr><td>List the files you’ve changed and those you still need to add or commit</td><td><code>git status</code></td></tr><tr><td>Add all or one file to staging</td><td><code>git add .</code> OR <code>git add file_name</code></td></tr><tr><td>Commit changes to head with message</td><td><code>git commit -m 'message'</code></td></tr><tr><td>Commit any files you’ve added with <code>git add</code>, and also commit any files you’ve changed since then</td><td><code>git commit -a</code></td></tr><tr><td>Send all commits from local repository to remote repository</td><td><code>git push</code></td></tr><tr><td>Do a <code>git push</code> and sets the default remote branch for the current local branch. So any future <code>git pull</code> command will attempt to bring in commits from the <code><remote-branch></code>into the current local branch</td><td><code>git push -u <remote-branch></code></td></tr><tr><td>Send changes to the master branch of your remote repository</td><td><code>git push origin master</code></td></tr><tr><td>Push a specific branch to your remote repository</td><td><code>git push origin <branch_name></code></td></tr><tr><td>Push all branches to your remote repository</td><td><code>git push --all origin</code></td></tr></tbody></table></figure><h2 class="wp-block-heading" id="working-with-the-git-workflow"><span id="Working_with_the_Git_Workflow">Working with the Git Workflow</span></h2><p>The following steps are based on a branching model, described <a href="https://nvie.com/posts/a-successful-git-branching-model/">here</a>.</p><figure class="wp-block-table"><table><tbody><tr><th>Name</th><th> Beschreibung</th></tr><tr><td>master</td><td></td></tr><tr><td>hotfixes</td></tr><tr><td>release</td></tr><tr><td>develop</td></tr><tr><td>feature</td></tr></tbody></table></figure><h3 class="wp-block-heading" id="Workflow-MitBranchesarbeiten"><span id="Working_with_branches">Working with branches</span></h3><h4 class="wp-block-heading" id="Workflow-Brancheserstellen"><span id="Create_branch_8216develop8217">Create branch ‘develop’</span></h4><pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">$ git clone git@github.com:<USER>/<REPO>.git develop
$ cd develop
$ git checkout -b develop
$ git push --set-upstream origin develop</pre><h4 class="wp-block-heading" id="create-branch-feature-xxx"><span id="Create_branch_8216feature-xxx8217">Create branch ‘feature-xxx’</span></h4><p>We dont’t want do clone the whole repository, but only the files needed for the feature</p><pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">$ git clone -b develop -n --depth 1 git@github.com:<USER>/<REPO>.git feature-2.2.0
$ cd feature-2.2.0
</pre><h4 class="wp-block-heading" id="Workflow-Branchlöschen"><span id="Branch_loschen">Branch löschen</span></h4><pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">$ git push origin -delete hotfix-1.2.1-compress-data</pre><h3 class="wp-block-heading" id="Workflow-Workflow-Cheatsheet"><span id="Workflow_8211_Cheatsheet">Workflow – Cheatsheet</span></h3><h4 class="wp-block-heading" id="working-with-branches"><span id="Working_with_branches-2">Working with branches</span></h4><p><strong>How to rename git local and remote branches</strong></p><div class="wp-block-columns has-2-columns is-layout-flex wp-container-core-columns-is-layout-3 wp-block-columns-is-layout-flex"><div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow"><p>Check out branch with old name</p></div><div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow"><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">git checkout feature-2.1.2</pre></div></div><div class="wp-block-columns has-2-columns is-layout-flex wp-container-core-columns-is-layout-4 wp-block-columns-is-layout-flex"><div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow"><p>Rename branch</p></div><div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow"><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">git branch -m feature-2.01.02</pre></div></div><div class="wp-block-columns has-2-columns is-layout-flex wp-container-core-columns-is-layout-5 wp-block-columns-is-layout-flex"><div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow"><p>Checkin branch with new name</p></div><div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow"><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">git push origin :feature-2.1.2 feature-2.01.02</pre></div></div><p><strong>1. Rename your local branch.</strong></p><p>If you have named a branch incorrectly AND pushed this to the remote repository follow these steps before any other developers get a chance to jump on you and give you shit for not correctly following naming conventions.</p><p>If you are on the branch you want to rename:</p><pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">git branch -m new-name</pre><p>If you are on a different branch:</p><pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">git branch -m old-name new-name</pre><p><strong>2. Delete the old-name remote branch and push the new-name local branch.</strong></p><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">git push origin :old-name new-name</pre><p><strong>3. Reset the upstream branch for the new-name local branch.</strong>Switch to the branch and then:</p><pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">git push origin -u new-name</pre><p>Or you as a fast way to do that, you can use these 3 steps: command in your terminal</p><pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">git branch -m old_branch new_branch # Rename branch locally
git push origin :old_branch # Delete old branch
git push --set-upstream origin new_branch # Push new branch, set local branch to track new remote</pre><figure class="wp-block-table"><table><tbody><tr><th>Neues Feature erstellen</th></tr><tr><td>Repository clonen</td><td>$ git checkout -b feature-1.2.2 develop</td></tr><tr><td>Änderungen durchführen</td></tr><tr><td>Änderungen einchecken</td><td>$ git checkout develop<br>$ git merge –no-ff feature-1.2.2 <br>$ git branch -d feature-1.2.2 <br>$ git push origin develop</td></tr><tr></tr></tbody></table></figure><figure class="wp-block-table"><table><tbody><tr><th>Neuen Hotfix erstelllen</th></tr><tr><td>Repository auschecken</td><td>$ git checkout -b hotfix-1.2.1 master</td></tr><tr><td>Änderungen durchführen</td></tr><tr><td>Änderungen einchecken</td><td>$ git commit -a -m “hotfix: hotfix-1.2.1| compress mart”</td></tr><tr><td>Hotfix beenden</td><td>$ git checkout master<br>$ git merge –no-ff hotfix-1.2.1 <br>$ git tag -a 1.2.1</td></tr><tr><td>Hotfix in Master einchecken</td><td>$ git checkout develop<br>$ git merge –no-ff hotfix-1.2.1 </td></tr><tr><td>Hotfix Branch entfernen</td><td>$ git branch -d hotfix-1.2.1</td></tr><tr></tr></tbody></table></figure><figure class="wp-block-table"><table><tbody><tr><th>Neues Release erstellen:</th></tr><tr><td>Repository clonen</td><td>$ git checkout -b release-1.2 develop</td></tr><tr><td>Änderungen durchführen</td></tr><tr><td>Änderungen einchecken</td><td>$ git commit -a -m “release: changes for release 1.2”</td></tr><tr><td>Release beenden</td><td>$ git checkout master<br>$ git merge –no-ff release-1.2<br>$ git tag -a 1.2</td></tr></tbody></table></figure><h2 class="wp-block-heading" id="git-flow"><span id="Git_Flow">Git Flow</span></h2><h4 class="wp-block-heading" id="initialize"><span id="Initialize">Initialize</span></h4><p>Start using git-flow by initializing it inside an existing git repository:</p><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">$ git flow init</pre><h4 class="wp-block-heading" id="start-a-new-feature"><span id="Start_a_new_feature">Start a new feature</span></h4><p>Development of new features starting from the ‘develop’ branch.</p><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">git flow feature start MYFEATURE</pre><h4 class="wp-block-heading" id="finish-up-a-feature"><span id="Finish_up_a_feature">Finish up a feature</span></h4><p>Finish the development of a feature. This action performs the following</p><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">git flow feature finish MYFEATURE</pre><h4 class="wp-block-heading" id="publish-a-feature"><span id="Publish_a_feature">Publish a feature</span></h4><p>Publish a feature to the remote server so it can be used by other users.</p><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">git flow feature publish MYFEATURE</pre><h3 class="wp-block-heading" id="getting-a-published-feature"><span id="Getting_a_published_feature">Getting a published feature</span></h3><p>Get a feature published by another user.</p><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">git flow feature pull origin MYFEATURE</pre><p>You can track a feature on origin by using</p><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">git flow feature track MYFEATURE</pre><h4 class="wp-block-heading" id="start-a-release"><span id="Start_a_release">Start a release</span></h4><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">git flow release start RELEASE [BASE]</pre><p>It’s wise to publish the release branch after creating it to allow release commits by other developers. Do it similar to feature publishing with the command:</p><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">git flow release publish RELEASE</pre><p>(You can track a remote release with the <br><code>git flow release track RELEASE</code>command)</p><h4 class="wp-block-heading" id="finish-up-a-release"><span id="Finish_up_a_release">Finish up a release</span></h4><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">git flow release finish RELEASE</pre><p>Don’t forget to push your tags with <code>git push origin --tags</code></p><h4 class="wp-block-heading" id="hotfixes"><span id="Hotfixes">Hotfixes</span></h4><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">git flow hotfix start VERSION [BASENAME]</pre><h4 class="wp-block-heading" id="finish-a-hotfix"><span id="Finish_a_hotfix">Finish a hotfix</span></h4><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">git flow hotfix finish VERSION</pre><h2 class="wp-block-heading" id="usefull-commands"><span id="Usefull_commands">Usefull commands</span></h2><figure class="wp-block-table"><table><tbody><tr><th>basic commands</th><th>description</th></tr><tr><td>git init</td></tr><tr><td>git status [ -s ]</td><td>status of files and local repo</td></tr><tr><td>git ls-files</td><td>show files which are tracked by git</td></tr><tr><td>git log [ –oneline ]<br>git log [–oneline –graph –decorate –all]</td><td>shows commit history</td></tr><tr><td>git add <changed file><br>git add .git add -u</td><td>add single file to indexadd all files from the workspace to indexstage current workspace into index to cleanup inconsistencies</td></tr><tr><td>git commit [ -m ‘message’ ]</td><td>commit into local repo only</td></tr><tr><td>git push -u origin master</td><td>push the repo from local to remote repo</td></tr><tr><td>git help [option]</td><td>get help page for specific options</td></tr><tr><td>git config –global alias.bla “command”<br>git bla [– <filename>]</td><td>set alias bla to a specific commandexec alias (for specific file)</td></tr><tr><td>git mv fileA fileB<br>git commit -m “…..”</td><td>rename fileA to fileBand commit</td></tr><tr><td>git rm fileC<br>git commit -m “…..”</td><td>delete fileCand commit</td></tr><tr></tr><tr><th>advanced commands</th><th>description</th></tr><tr><td>git reset HEAD <filename></td><td>undo changes from index back to workspace</td></tr><tr><td>git checkout <filename><br>git checkout master<br>git checkout <branchname></td><td>checkout single file from local repo to workspacecheckout/switch to the master branchcheckout/switch to another branch</td></tr><tr><td>git checkout -b <new branchname><br>git branch <new branchname></td><td>create new branch and switch to it immediatelycreate new branch in the background, doesn’t switch to it</td></tr><tr><td>git branch</td><td>shows all available branches</td></tr><tr><td>git diff<br>git difftool</td><td>show differences of local and committed file<br>shows diff in vimdiff</td></tr><tr><td>git merge <other branch><br>git mergetool</td><td>merge other branch into master (current branch)manage the different files in vimdiff</td></tr><tr><td>git branch -d <branchname></td><td>delete branch (does NOT include merge)</td></tr><tr><td>git branch -m <new name></td><td>rename a</td></tr><tr><td>$ git diff master..development</td><td>compare two branches</td></tr><tr><td>git tag <mytag><br>git tag -a v1.0 -m “description”<br>git show v1.0</td><td>add an additional label/tag to a branchannotation tag with release informationshows details of tag v1.0</td></tr><tr><td>git stash</td></tr><tr><td>git reset <ID> [–soft | –mixed | –hard]<br>git reflog ….</td></tr><tr><td>git fetch ….</td><td>update local repo with changes from remote repo. (non destructive)</td></tr><tr><td>git pull …</td><td>update local repo with changes from remote repo. it does effectively a fetch and merge in one command</td></tr><tr><td>git clone https://<<em>username</em>>:<<em>token</em>>@github.com/<<em>organisation-space</em>>/<<em>repository</em>><br></td><td>download the remote repo into local workspace</td></tr><tr><td>git remote -v<br>git remote show origin</td><td>shows url of remote reposhows detail infos of a remote repo</td></tr><tr></tr><tr><td>.gitignore</td><td>contains filename to exclude from git</td></tr></tbody></table></figure><h2 class="wp-block-heading" id="git-workflow"><span id="Git_Workflow">Git Workflow</span></h2><h3 class="wp-block-heading" id="release"><span id="Release">Release</span></h3><h4 class="wp-block-heading" id="creating-a-release-branch"><span id="Creating_a_release_branch">Creating a release branch</span></h4><div class="wp-block-columns has-2-columns is-layout-flex wp-container-core-columns-is-layout-6 wp-block-columns-is-layout-flex"><div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow"><p> Release branches are created from the <code>develop</code> branch. For example, say version 1.1.5 is the current production release and we have a big release coming up. The state of <code>develop</code>is ready for the “next release” and we have decided that this will become version 1.2 (rather than 1.1.6 or 2.0). So we branch off and give the release branch a name reflecting the new version number:</p></div><div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow"><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">$ git checkout -b release-1.2 develop</pre></div></div><div class="wp-block-columns has-2-columns is-layout-flex wp-container-core-columns-is-layout-7 wp-block-columns-is-layout-flex"><div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow"><p>After creating a new branch and switching to it, we bump the version number. Here, <code>bump-version.sh</code> is a fictional shell script that changes some files in the working copy to reflect the new version. (This can of course be a manual change—the point being that <em>some</em> files change.) Then, the bumped version number is committed.</p><p>This new branch may exist there for a while, until the release may be rolled out definitely. During that time, bug fixes may be applied in this branch (rather than on the <code>develop</code>branch). Adding large new features here is strictly prohibited. They must be merged into <code>develop</code>, and therefore, wait for the next big release.</p></div><div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow"><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">$ ./bump-version.sh 1.2<br>
$ git commit -a -m "Version 1.2"</pre></div></div><h4 class="wp-block-heading" id="finishing-a-release-branch"><span id="Finishing_a_release_branchnbsp"> Finishing a release branch </span></h4><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">$ git checkout master
$ git merge --no-ff release-1.2
$ git tag -a 1.2
$ git checkout develop
$ git merge --no-ff release-1.2
$ git branch -d release-1.2</pre><div class="wp-block-columns has-2-columns is-layout-flex wp-container-core-columns-is-layout-8 wp-block-columns-is-layout-flex"><div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow"><p>When the state of the release branch is ready to become a real release, some actions need to be carried out.</p><p>First, the release branch is merged into <code>master</code> (since every commit on <code>master</code> is a new release <em>by definition</em>, remember).</p><p>Next, that commit on <code>master</code> must be tagged for easy future reference to this historical version.</p><p>Finally, the changes made on the release branch need to be merged back into <code>develop</code>, so that future releases also contain these bug fixes.</p></div><div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow"><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">$ git checkout master
$ git merge --no-ff release-1.2
$ git tag -a 1.2</pre></div></div><div class="wp-block-columns has-2-columns is-layout-flex wp-container-core-columns-is-layout-9 wp-block-columns-is-layout-flex"><div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow"><p>The release is now done, and tagged for future reference.</p><p>To keep the changes made in the release branch, we need to merge those back into <code>develop</code>, though. In Git:</p></div><div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow"><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">$ git checkout develop
$ git merge --no-ff release-1.2</pre></div></div><div class="wp-block-columns has-2-columns is-layout-flex wp-container-core-columns-is-layout-10 wp-block-columns-is-layout-flex"><div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow"><p>This step may well lead to a merge conflict (probably even, since we have changed the version number). If so, fix it and commit.</p><p>Now we are really done and the release branch may be removed, since we don’t need it anymore:</p></div><div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow"><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">$ git branch -d release-1.2</pre></div></div><h3 class="wp-block-heading" id="feature"><span id="Feature">Feature</span></h3><figure class="wp-block-image"><img decoding="async" src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%201%201'%3E%3C/svg%3E" data-src="http://blog.via-internet.de/wp-content/uploads/2019/03/fb@2x-e1554287024987-700x261.png" alt="" class="wp-image-4387 lazy"></figure><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">$ git checkout -b myfeature develop
$ .. do changes...
$ git checkout develop
$ git merge --no-ff myfeature
$ git branch -d myfeature
$ git push origin develop</pre><div class="wp-block-columns has-2-columns is-layout-flex wp-container-core-columns-is-layout-11 wp-block-columns-is-layout-flex"><div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow"><h4 class="wp-block-heading" id="creating-a-feature-branch"><span id="Creating_a_feature_branchnbsp">Creating a feature branch </span></h4><p>When starting work on a new feature, branch off from the <code>develop</code> branch.</p><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">$ git checkout -b myfeature develop
Switched to a new branch "myfeature"
</pre><h4 class="wp-block-heading" id="incorporating-a-finished-feature-on-develop"><span id="Incorporating_a_finished_feature_on_developnbsp">Incorporating a finished feature on develop </span></h4><p>Finished features may be merged into the <code>develop</code> branch to definitely add them to the upcoming release:</p><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">$ git checkout develop<
$ git merge --no-ff myfeature
$ git branch -d myfeature
$ git push origin develop </pre></div><div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow"></div></div><div class="wp-block-columns has-2-columns is-layout-flex wp-container-core-columns-is-layout-12 wp-block-columns-is-layout-flex"><div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow"><p> The <code>--no-ff</code> flag causes the merge to always create a new commit object, even if the merge could be performed with a fast-forward. This avoids losing information about the historical existence of a feature branch and groups together all commits that together added the feature.</p><p>In the latter case, it is impossible to see from the Git history which of the commit objects together have implemented a feature—you would have to manually read all the log messages. Reverting a whole feature (i.e. a group of commits), is a true headache in the latter situation, whereas it is easily done if the <code>--no-ff</code> flag was used.</p></div><div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow"><figure class="wp-block-image"><img class="lazy" decoding="async" src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%201%201'%3E%3C/svg%3E" data-src="https://nvie.com/img/merge-without-ff@2x.png" alt=""></figure></div></div><h2 class="wp-block-heading" id="hotfix"><span id="Hotfix">Hotfix</span></h2><figure class="wp-block-image"><img decoding="async" src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%201%201'%3E%3C/svg%3E" data-src="http://blog.via-internet.de/wp-content/uploads/2019/03/hotfix-branches@2x-e1554287153961-700x519.png" alt="" class="wp-image-4394 lazy"></figure><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">$ git checkout -b hotfix-1.2.1 master
$ ... do changes ...
$ git commit -a -m "Hotfix Version 1.2.1"
$ .. fix bug
$ git commit -m "Fixed severe production problem"
$ git checkout master
$ git merge --no-ff hotfix-1.2.1
$ git tag -a 1.2.1
# incude hotfix into develop
$ git checkout develop
$ git merge --no-ff hotfix-1.2.1
# finally, remove hotfix branch
$ git branch -d hotfix-1.2.1</pre><h2 class="wp-block-heading" id="troubleshooting"><span id="Troubleshooting">Troubleshooting</span></h2><h4 class="wp-block-heading" id="debugging-github-errors"><span id="Debugging_Github_Errors">Debugging Github Errors</span></h4><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">export GIT_TRACE_PACKET=1
export GIT_TRACE=1
export GIT_CURL_VERBOSE=1</pre><h4 class="wp-block-heading" id="error-message-your-local-changes-to-the-following-files-would-be-overwritten-by-merge"><span id="Error_Message_Your_local_changes_to_the_following_files_would_be_overwritten_by_merge">Error Message: Your local changes to the following files would be overwritten by merge: </span></h4><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">error: Your local changes to the following files would be overwritten by merge:<br>
README.md<br>
Please commit your changes or stash them before you merge.</pre><h4 class="wp-block-heading" id="solution"><span id="Solution">Solution:</span></h4><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">$ git fetch origin master
$ git diff origin/master -- [local-path]</pre><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">$ git add [local-path]
$ gt commit -m "change: in file [local-path]"</pre><h4 class="wp-block-heading" id="fatal-sha1-file-stdout-write-error-broken-pipe"><span id="fatal_sha1_file_8216ltstdoutgt8217_write_error_Broken_Pipe">fatal: sha1 file ‘<stdout>’ write error: Broken Pipe </span></h4><p>When using ssh to connect to the repositoriy, sometime, you got a timeout if you push to many files or if the files are to big</p><h4 class="wp-block-heading" id="one-possible-solution"><span id="One_possible_Solution">One possible Solution</span></h4><p>Configure ssh to use the following value</p><pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">~/.ssh/config</pre><pre class="EnlighterJSRAW" data-enlighter-language="ini" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">Host *
ServerAliveInterval 30
ServerAliveCountMax 4</pre><h4 class="wp-block-heading" id="git-clone-file-name-to-long-on-windows"><span id="git_clone_file_name_to_long_on_windows">git clone: file name to long on windows</span></h4><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">git config --system core.longpaths true</pre><h4 class="wp-block-heading" id="git-config-global-user-email-some-email-com-throws-error-only-one-config-file-at-a-time"><span id="git_config_8211global_useremail_someemailcom_throws_error_only_one_config_file_at_a_time">git config –global user.email “some@email.com” throws “error: only one config file at a time.</span></h4><p>Try to unset GIT_CONFIG and then list your global config with</p><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">unset GIT_CONFIG
git config --global --list</pre><p>Other Links</p><p><a href="https://medium.com/flawless-app-stories/useful-git-commands-for-everyday-use-e1a4de64037d">Useful Git commands for everyday use</a></p><p><a href="https://medium.com/android-bits/10-useful-git-commands-you-always-need-b0d0a50b81e6">10 useful Git commands you always need</a></p><p><a href="https://orga.cat/posts/most-useful-git-commands">Most useful Git commands</a></p><p><a href="https://artandlogic.com/2014/01/git-cheat-sheet/">Git Cheat Sheet</a></p><p><a href="https://dzone.com/articles/useful-git-commands">Useful Git commands</a></p><h2 class="wp-block-heading" id="using-local-filesystem-as-respository-master"><span id="Using_local_Filesystem_as_Respository-Master">Using local Filesystem as Respository-Master</span></h2><h4 class="wp-block-heading" id="preparation"><span id="Preparation">Preparation</span></h4><p>Set environment variables for easy typing</p><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">$ REPOS=$HOME/repos</pre><h4 class="wp-block-heading" id="create-repository"><span id="Create_Repository">Create Repository</span></h4><pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">$ mkdir $REPOS
$ cd $REPOS</pre><pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">$ git init --bare src</pre><h4 class="wp-block-heading" id="create-src-folder"><span id="Create_src_folder">Create src folder</span></h4><pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">$ mkdir $HOME/entw
$ cd $HOME/entw
$ mkdir src
$ cd src
$ git init</pre><h4 class="wp-block-heading" id="create-some-content"><span id="Create_some_content">Create some content</span></h4><pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">$ touch README.md</pre><pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">$ git add -A</pre><pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">$ git commit -m "initial commit"</pre><pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">$ git remote add origin $REPOS/src
$ git remote -v
$ git push --set-upstream origin master
$ git push origin master</pre><h4 class="wp-block-heading" id="create-clone"><span id="Create_clone">Create clone</span></h4><pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">$ mkdir $HOME/test
$ cd $HOME/test</pre><pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">$ git clone $HOME/repos/src</pre><pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">$ cd src
$ ls -al
total 0
drwxr-xr-x 4 user wheel 128 19 Mär 18:48 .
drwxr-xr-x 3 user wheel 96 19 Mär 18:48 ..
drwxr-xr-x 12 user wheel 384 19 Mär 18:48 .git
-rw-r--r-- 1 user wheel 0 19 Mär 18:48 README.md</pre><p>You will notice, that the file README.md is empty. Because it was ony created with touch.</p><h4 class="wp-block-heading" id="add-some-content-to-source-repository"><span id="Add_some_content_to_source_repository">Add some content to source repository</span></h4><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">$ cd $HOME/entw/src
$ echo "# This is the README.md from ENTW" >README.md
$ touch git_update
$ touch git_push</pre><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">$ ls -al
total 16
drwxr-xr-x 6 user wheel 192 19 Mär 18:53 .
drwxr-xr-x 3 user wheel 96 19 Mär 18:43 ..
drwxr-xr-x 12 user wheel 384 19 Mär 18:47 .git
-rw-r--r-- 1 user wheel 34 19 Mär 18:52 README.md
-rw-r--r-- 1 user wheel 0 19 Mär 18:53 git_push
-rw-r--r-- 1 user wheel 0 19 Mär 18:53 git_update</pre><h4 class="wp-block-heading" id="add-changes-to-repository"><span id="Add_changes_to_repository">Add changes to repository</span></h4><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">$ git add -A
$ git commit -m "-"
[master 106b27a] -
3 files changed, 1 insertion(+)
create mode 100644 git_push
create mode 100644 git_update</pre><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">$ git push --set-upstream origin master
Objekte aufzählen: 5, Fertig.
Zähle Objekte: 100
Delta-Kompression verwendet bis zu 8 Threads.
Komprimiere Objekte: 100
Schreibe Objekte: 100
Gesamt 3 (Delta 0), Wiederverwendet 0 (Delta 0)
To ..../repos/src
7ed6d3b..106b27a master -> master
Branch 'master' folgt nun Remote-Branch 'master' von 'origin'.</pre><h4 class="wp-block-heading" id="update-clone"><span id="Update_clone">Update clone</span></h4><pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">$ cd $OME/test/src
$ git pull
# git fetch # This updates 'remote' portion of local repo.
# git reset --hard origin/<your-working-branch>
remote: Objekte aufzählen: 5, Fertig.
remote: Zähle Objekte: 100
remote: Komprimiere Objekte: 100
remote: Gesamt 3 (Delta 0), Wiederverwendet 0 (Delta 0)
Entpacke Objekte: 100
Von .../repos/src
7ed6d3b..106b27a master -> origin/master</pre><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">$ git merge origin/master
Aktualisiere 7ed6d3b..106b27a
Fast-forward
README.md | 1 +
git_push | 0
git_update | 0
3 files changed, 1 insertion(+)
create mode 100644 git_push
create mode 100644 git_update</pre><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">$ ls -al
total 16
drwxr-xr-x 6 user wheel 192 19 Mär 19:02 .
drwxr-xr-x 3 user wheel 96 19 Mär 18:48 ..
drwxr-xr-x 14 user wheel 448 19 Mär 19:02 .git
-rw-r--r-- 1 user wheel 34 19 Mär 19:02 README.md
-rw-r--r-- 1 user wheel 0 19 Mär 19:02 git_push
-rw-r--r-- 1 user wheel 0 19 Mär 19:02 git_update</pre><h2 class="wp-block-heading" id="todo"><span id="TODO">TODO</span></h2><h4 class="wp-block-heading" id="see-changes-before-pulling-from-remote-git-repositoryf"><span id="See_changes_before_pulling_from_remote_git_repositoryf">See changes before pulling from remote git repository<a href="https://gist.github.com/jtdp/5443297#file-gistfile1-sh"><strong>f</strong></a></span></h4><figure class="wp-block-table"><table><tbody><tr><td># fetch the changes from the remote</td></tr><tr><td>git fetch origin</td></tr><tr></tr><tr><td># show commit logs of changes</td></tr><tr><td>git log master..origin/master</td></tr><tr></tr><tr><td># show diffs of changes</td></tr><tr><td>git diff master..origin/master</td></tr><tr></tr><tr><td># apply the changes by merge..</td></tr><tr><td>git merge origin/master</td></tr><tr></tr><tr><td># .. or just pull the changes</td></tr><tr><td>git pull</td></tr></tbody></table></figure><h4 class="wp-block-heading" id="you-want-to-push-your-local-files-to-remote-files"><span id="You_want_to_push_your_local_files_to_remote_files">You want to push your local files to remote files</span></h4><pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">git push -f <remote> <branch></pre><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">git push -f origin master</pre><h3 class="wp-block-heading" id="configure-hooks"><span id="Configure_Hooks">Configure Hooks</span></h3><pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">git config --global core.hooksPath .githooks
mkdir .githooks
cp .git/hooks/* .githooks</pre><h4 class="wp-block-heading" id="prepare-commit"><span id="commit-msg">commit-msg</span></h4><pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">#!/bin/sh
#
NAME=$(git rev-parse --abbrev-ref HEAD)
DESCRIPTION=$(git config branch."$NAME".description)
echo "$NAME"': '$(cat "$1") > "$1"
if [ -n "$DESCRIPTION" ]
then
echo "" >> "$1"
echo $DESCRIPTION >> "$1"
fi</pre><h4 class="wp-block-heading" id="prepare-commit"><span id="prepare-commit">prepare-commit</span></h4><pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">#!/bin/sh
#
COMMIT_MSG_FILE=$1
COMMIT_SOURCE=$2
SHA1=$3
branchPath=$(git symbolic-ref -q HEAD)
branchName=${branchPath##*/}
if [ -n "$branchName" ]; then
echo "$branchName | $(cat $1)" > $1
fi</pre><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">file=$(git config hooks.versionfilename)
if [[ -z $file ]]
then
file=".version"
fi
# Version number
echo "$(git rev-parse --abbrev-ref HEAD): $(git describe --tags --long)" >$file
exec git add $file</pre><h4 class="wp-block-heading" id="pre-commit"><span id="pre-commit">pre-commit</span></h4><pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">#!/bin/sh
_BRANCHPATH=$(git symbolic-ref -q HEAD)
_BRANCHNAME=${_BRANCHPATH##*/}
_TIMESTAMP="$(date '+
echo "HOOK : $0"
echo "PARAMETER : '$*''"
echo "BRANCHPATH: $_BRANCHPATH"
echo "BRANCHNAME: $_BRANCHNAME"
LOG() {
[[ "$GIT_COMMIT_DETAILED_LOGGING" == "YES" ]] && echo "LOG: $*"
}
REPLACE()
{
local _TYP; _TYP="$1"; shift
local _TAG; _TAG="$1"; shift
local _WITH; _WITH="$1"; shift
local _FILE; _FILE="$1"; shift
case "$_TYP" in
PYTHON) perl -pi -e 's/(\s*)(__DEPLOY_'${_TAG}'\s*=\s*)(".+")/${1}${2}"'"${_WITH}"'"/' "${_FILE}"
;;
*) LOG "Undefined typ '$TYP' for file $_FILE"
;;
esac
rm -f "${_FILE}.bak"
}
LOG "working on branch $_BRANCH"
for _FILE in $(git diff-index --name-status --cached HEAD | grep -v ^D | cut -c3-)
do
LOG "checking: $_FILE"
# Only examine known text files
if [[ "$_FILE" =~ [.](py)$ ]]; then
LOG "patching: $_FILE"
REPLACE PYTHON TAG "$_BRANCHNAME" "$_FILE"
REPLACE PYTHON TIMESTAMP "$_TIMESTAMP" "$_FILE"
fi
done
</pre><h2 class="wp-block-heading" id="get-information"><span id="Get_Information">Get Information</span></h2><figure class="wp-block-table"><table><tbody><tr><td>git rev-parse –abbrev-ref HEAD</td><td>get branch name</td><td>feature/add-new-content</td></tr><tr><td>git symbolic-ref -q HEAD</td><td></td><td>refs/heads/<meta charset="utf-8">feature/add-new-content</td></tr><tr><td><meta charset="utf-8">git rev-parse –show-toplevel</td><td><meta charset="utf-8">show current path of git repository</td><td></td></tr><tr><td></td><td></td><td></td></tr><tr><td></td><td></td><td></td></tr></tbody></table></figure><h2 class="wp-block-heading" id="config"><span id="Config">Config</span></h2><h3 class="wp-block-heading" id="change-github-repository-for-local-clone"><span id="Change_Github_repository_for_local_clone">Change Github repository for local clone</span></h3><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">cd <original repository>
git remote set-url origin https://github.com/<new git user>/<new project name>
git push -u origin master
</pre><h3 class="wp-block-heading" id="cr-lf-mapping"><span id="CRLF_Mapping">CR/LF Mapping</span></h3><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">git config core.autocrlf true
git config --global core.safecrlf false</pre><h2 class="wp-block-heading" id="create-release"><span id="Create_Release">Create Release</span></h2><pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">#!/bin/bash
if [ $# -ne 1 ]; then
echo "Syntax: release [VERSION]"
exit 1
fi
VERSION=$1
# Create release
git flow release start $VERSION || exit 1
GIT_MERGE_AUTOEDIT=no git flow release finish -m $VERSION $VERSION
# Publish release
git push origin HEAD --tags
# Merge release into develop
git checkout develop
git merge master</pre>
git ls-files -z | xargs -0 -n1 -I{} -- git log -1 --format=" <h2 class="wp-block-heading" id="git-configuration"><span id="Git_Configuration">Git Configuration</span></h2> <h3 class="wp-block-heading" id="show-location-of-configuration-files"><span id="Show_location_of_configuration_files">Show location of configuration files</span></h3> <pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">git config --list --show-origin</pre><p>This dows not work, if you have set the environment var GIT_CONFIG. In this case, do</p><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">unset GIT_CONFIG git config --global --list</pre><h2 class="wp-block-heading" id="edit-config-files"><span id="Edit_config_files">Edit config files</span></h2><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">git config --edit --global</pre><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">git config --edit --system</pre><figure class="wp-block-table"><table><thead><tr><th>DESCRIPTION</th><th>GIT COMMAND</th></tr></thead><tbody><tr><td>Configure the author name to be used with your commits.</td><td><code>git config --global user.name "XXX"</code></td></tr><tr><td>Configure the author email address to be used with your commits</td><td><code>git config --global user.email xxx@example.com</code></td></tr><tr><td>Will remove user credential details from the repository</td><td><code>git config --local credential.helper ""</code></td></tr><tr><td></td><td>git config —show-origin</td></tr><tr><td>List all currently configured remote repository URLs</td><td><code>git remote -v</code></td></tr><tr><td>If you haven’t connected your local repository to a remote server, To add a remote server to a local repository</td><td><code>git remote add origin <repo_url></code></td></tr></tbody></table></figure><h2 class="wp-block-heading" id="git-commit-and-push"><span id="Git_Commit_and_Push">Git Commit and Push</span></h2><figure class="wp-block-table"><table><thead><tr><th>DESCRIPTION</th><th>GIT COMMAND</th></tr></thead><tbody><tr><td>Create a file name <code>README.md</code> with <code>Readme content</code> content</td><td><code>echo "Readme content" >> README.md</code></td></tr><tr><td>List the files you’ve changed and those you still need to add or commit</td><td><code>git status</code></td></tr><tr><td>Add all or one file to staging</td><td><code>git add .</code> OR <code>git add file_name</code></td></tr><tr><td>Commit changes to head with message</td><td><code>git commit -m 'message'</code></td></tr><tr><td>Commit any files you’ve added with <code>git add</code>, and also commit any files you’ve changed since then</td><td><code>git commit -a</code></td></tr><tr><td>Send all commits from local repository to remote repository</td><td><code>git push</code></td></tr><tr><td>Do a <code>git push</code> and sets the default remote branch for the current local branch. So any future <code>git pull</code> command will attempt to bring in commits from the <code><remote-branch></code>into the current local branch</td><td><code>git push -u <remote-branch></code></td></tr><tr><td>Send changes to the master branch of your remote repository</td><td><code>git push origin master</code></td></tr><tr><td>Push a specific branch to your remote repository</td><td><code>git push origin <branch_name></code></td></tr><tr><td>Push all branches to your remote repository</td><td><code>git push --all origin</code></td></tr></tbody></table></figure><h2 class="wp-block-heading" id="working-with-the-git-workflow"><span id="Working_with_the_Git_Workflow">Working with the Git Workflow</span></h2><p>The following steps are based on a branching model, described <a href="https://nvie.com/posts/a-successful-git-branching-model/">here</a>.</p><figure class="wp-block-table"><table><tbody><tr><th>Name</th><th> Beschreibung</th></tr><tr><td>master</td><td></td></tr><tr><td>hotfixes</td></tr><tr><td>release</td></tr><tr><td>develop</td></tr><tr><td>feature</td></tr></tbody></table></figure><h3 class="wp-block-heading" id="Workflow-MitBranchesarbeiten"><span id="Working_with_branches">Working with branches</span></h3><h4 class="wp-block-heading" id="Workflow-Brancheserstellen"><span id="Create_branch_8216develop8217">Create branch ‘develop’</span></h4><pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">$ git clone git@github.com:<USER>/<REPO>.git develop $ cd develop $ git checkout -b develop $ git push --set-upstream origin develop</pre><h4 class="wp-block-heading" id="create-branch-feature-xxx"><span id="Create_branch_8216feature-xxx8217">Create branch ‘feature-xxx’</span></h4><p>We dont’t want do clone the whole repository, but only the files needed for the feature</p><pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">$ git clone -b develop -n --depth 1 git@github.com:<USER>/<REPO>.git feature-2.2.0 $ cd feature-2.2.0 </pre><h4 class="wp-block-heading" id="Workflow-Branchlöschen"><span id="Branch_loschen">Branch löschen</span></h4><pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">$ git push origin -delete hotfix-1.2.1-compress-data</pre><h3 class="wp-block-heading" id="Workflow-Workflow-Cheatsheet"><span id="Workflow_8211_Cheatsheet">Workflow – Cheatsheet</span></h3><h4 class="wp-block-heading" id="working-with-branches"><span id="Working_with_branches-2">Working with branches</span></h4><p><strong>How to rename git local and remote branches</strong></p><div class="wp-block-columns has-2-columns is-layout-flex wp-container-core-columns-is-layout-3 wp-block-columns-is-layout-flex"><div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow"><p>Check out branch with old name</p></div><div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow"><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">git checkout feature-2.1.2</pre></div></div><div class="wp-block-columns has-2-columns is-layout-flex wp-container-core-columns-is-layout-4 wp-block-columns-is-layout-flex"><div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow"><p>Rename branch</p></div><div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow"><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">git branch -m feature-2.01.02</pre></div></div><div class="wp-block-columns has-2-columns is-layout-flex wp-container-core-columns-is-layout-5 wp-block-columns-is-layout-flex"><div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow"><p>Checkin branch with new name</p></div><div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow"><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">git push origin :feature-2.1.2 feature-2.01.02</pre></div></div><p><strong>1. Rename your local branch.</strong></p><p>If you have named a branch incorrectly AND pushed this to the remote repository follow these steps before any other developers get a chance to jump on you and give you shit for not correctly following naming conventions.</p><p>If you are on the branch you want to rename:</p><pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">git branch -m new-name</pre><p>If you are on a different branch:</p><pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">git branch -m old-name new-name</pre><p><strong>2. Delete the old-name remote branch and push the new-name local branch.</strong></p><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">git push origin :old-name new-name</pre><p><strong>3. Reset the upstream branch for the new-name local branch.</strong>Switch to the branch and then:</p><pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">git push origin -u new-name</pre><p>Or you as a fast way to do that, you can use these 3 steps: command in your terminal</p><pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">git branch -m old_branch new_branch # Rename branch locally git push origin :old_branch # Delete old branch git push --set-upstream origin new_branch # Push new branch, set local branch to track new remote</pre><figure class="wp-block-table"><table><tbody><tr><th>Neues Feature erstellen</th></tr><tr><td>Repository clonen</td><td>$ git checkout -b feature-1.2.2 develop</td></tr><tr><td>Änderungen durchführen</td></tr><tr><td>Änderungen einchecken</td><td>$ git checkout develop<br>$ git merge –no-ff feature-1.2.2 <br>$ git branch -d feature-1.2.2 <br>$ git push origin develop</td></tr><tr></tr></tbody></table></figure><figure class="wp-block-table"><table><tbody><tr><th>Neuen Hotfix erstelllen</th></tr><tr><td>Repository auschecken</td><td>$ git checkout -b hotfix-1.2.1 master</td></tr><tr><td>Änderungen durchführen</td></tr><tr><td>Änderungen einchecken</td><td>$ git commit -a -m “hotfix: hotfix-1.2.1| compress mart”</td></tr><tr><td>Hotfix beenden</td><td>$ git checkout master<br>$ git merge –no-ff hotfix-1.2.1 <br>$ git tag -a 1.2.1</td></tr><tr><td>Hotfix in Master einchecken</td><td>$ git checkout develop<br>$ git merge –no-ff hotfix-1.2.1 </td></tr><tr><td>Hotfix Branch entfernen</td><td>$ git branch -d hotfix-1.2.1</td></tr><tr></tr></tbody></table></figure><figure class="wp-block-table"><table><tbody><tr><th>Neues Release erstellen:</th></tr><tr><td>Repository clonen</td><td>$ git checkout -b release-1.2 develop</td></tr><tr><td>Änderungen durchführen</td></tr><tr><td>Änderungen einchecken</td><td>$ git commit -a -m “release: changes for release 1.2”</td></tr><tr><td>Release beenden</td><td>$ git checkout master<br>$ git merge –no-ff release-1.2<br>$ git tag -a 1.2</td></tr></tbody></table></figure><h2 class="wp-block-heading" id="git-flow"><span id="Git_Flow">Git Flow</span></h2><h4 class="wp-block-heading" id="initialize"><span id="Initialize">Initialize</span></h4><p>Start using git-flow by initializing it inside an existing git repository:</p><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">$ git flow init</pre><h4 class="wp-block-heading" id="start-a-new-feature"><span id="Start_a_new_feature">Start a new feature</span></h4><p>Development of new features starting from the ‘develop’ branch.</p><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">git flow feature start MYFEATURE</pre><h4 class="wp-block-heading" id="finish-up-a-feature"><span id="Finish_up_a_feature">Finish up a feature</span></h4><p>Finish the development of a feature. This action performs the following</p><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">git flow feature finish MYFEATURE</pre><h4 class="wp-block-heading" id="publish-a-feature"><span id="Publish_a_feature">Publish a feature</span></h4><p>Publish a feature to the remote server so it can be used by other users.</p><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">git flow feature publish MYFEATURE</pre><h3 class="wp-block-heading" id="getting-a-published-feature"><span id="Getting_a_published_feature">Getting a published feature</span></h3><p>Get a feature published by another user.</p><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">git flow feature pull origin MYFEATURE</pre><p>You can track a feature on origin by using</p><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">git flow feature track MYFEATURE</pre><h4 class="wp-block-heading" id="start-a-release"><span id="Start_a_release">Start a release</span></h4><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">git flow release start RELEASE [BASE]</pre><p>It’s wise to publish the release branch after creating it to allow release commits by other developers. Do it similar to feature publishing with the command:</p><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">git flow release publish RELEASE</pre><p>(You can track a remote release with the <br><code>git flow release track RELEASE</code>command)</p><h4 class="wp-block-heading" id="finish-up-a-release"><span id="Finish_up_a_release">Finish up a release</span></h4><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">git flow release finish RELEASE</pre><p>Don’t forget to push your tags with <code>git push origin --tags</code></p><h4 class="wp-block-heading" id="hotfixes"><span id="Hotfixes">Hotfixes</span></h4><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">git flow hotfix start VERSION [BASENAME]</pre><h4 class="wp-block-heading" id="finish-a-hotfix"><span id="Finish_a_hotfix">Finish a hotfix</span></h4><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">git flow hotfix finish VERSION</pre><h2 class="wp-block-heading" id="usefull-commands"><span id="Usefull_commands">Usefull commands</span></h2><figure class="wp-block-table"><table><tbody><tr><th>basic commands</th><th>description</th></tr><tr><td>git init</td></tr><tr><td>git status [ -s ]</td><td>status of files and local repo</td></tr><tr><td>git ls-files</td><td>show files which are tracked by git</td></tr><tr><td>git log [ –oneline ]<br>git log [–oneline –graph –decorate –all]</td><td>shows commit history</td></tr><tr><td>git add <changed file><br>git add .git add -u</td><td>add single file to indexadd all files from the workspace to indexstage current workspace into index to cleanup inconsistencies</td></tr><tr><td>git commit [ -m ‘message’ ]</td><td>commit into local repo only</td></tr><tr><td>git push -u origin master</td><td>push the repo from local to remote repo</td></tr><tr><td>git help [option]</td><td>get help page for specific options</td></tr><tr><td>git config –global alias.bla “command”<br>git bla [– <filename>]</td><td>set alias bla to a specific commandexec alias (for specific file)</td></tr><tr><td>git mv fileA fileB<br>git commit -m “…..”</td><td>rename fileA to fileBand commit</td></tr><tr><td>git rm fileC<br>git commit -m “…..”</td><td>delete fileCand commit</td></tr><tr></tr><tr><th>advanced commands</th><th>description</th></tr><tr><td>git reset HEAD <filename></td><td>undo changes from index back to workspace</td></tr><tr><td>git checkout <filename><br>git checkout master<br>git checkout <branchname></td><td>checkout single file from local repo to workspacecheckout/switch to the master branchcheckout/switch to another branch</td></tr><tr><td>git checkout -b <new branchname><br>git branch <new branchname></td><td>create new branch and switch to it immediatelycreate new branch in the background, doesn’t switch to it</td></tr><tr><td>git branch</td><td>shows all available branches</td></tr><tr><td>git diff<br>git difftool</td><td>show differences of local and committed file<br>shows diff in vimdiff</td></tr><tr><td>git merge <other branch><br>git mergetool</td><td>merge other branch into master (current branch)manage the different files in vimdiff</td></tr><tr><td>git branch -d <branchname></td><td>delete branch (does NOT include merge)</td></tr><tr><td>git branch -m <new name></td><td>rename a</td></tr><tr><td>$ git diff master..development</td><td>compare two branches</td></tr><tr><td>git tag <mytag><br>git tag -a v1.0 -m “description”<br>git show v1.0</td><td>add an additional label/tag to a branchannotation tag with release informationshows details of tag v1.0</td></tr><tr><td>git stash</td></tr><tr><td>git reset <ID> [–soft | –mixed | –hard]<br>git reflog ….</td></tr><tr><td>git fetch ….</td><td>update local repo with changes from remote repo. (non destructive)</td></tr><tr><td>git pull …</td><td>update local repo with changes from remote repo. it does effectively a fetch and merge in one command</td></tr><tr><td>git clone https://<<em>username</em>>:<<em>token</em>>@github.com/<<em>organisation-space</em>>/<<em>repository</em>><br></td><td>download the remote repo into local workspace</td></tr><tr><td>git remote -v<br>git remote show origin</td><td>shows url of remote reposhows detail infos of a remote repo</td></tr><tr></tr><tr><td>.gitignore</td><td>contains filename to exclude from git</td></tr></tbody></table></figure><h2 class="wp-block-heading" id="git-workflow"><span id="Git_Workflow">Git Workflow</span></h2><h3 class="wp-block-heading" id="release"><span id="Release">Release</span></h3><h4 class="wp-block-heading" id="creating-a-release-branch"><span id="Creating_a_release_branch">Creating a release branch</span></h4><div class="wp-block-columns has-2-columns is-layout-flex wp-container-core-columns-is-layout-6 wp-block-columns-is-layout-flex"><div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow"><p> Release branches are created from the <code>develop</code> branch. For example, say version 1.1.5 is the current production release and we have a big release coming up. The state of <code>develop</code>is ready for the “next release” and we have decided that this will become version 1.2 (rather than 1.1.6 or 2.0). So we branch off and give the release branch a name reflecting the new version number:</p></div><div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow"><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">$ git checkout -b release-1.2 develop</pre></div></div><div class="wp-block-columns has-2-columns is-layout-flex wp-container-core-columns-is-layout-7 wp-block-columns-is-layout-flex"><div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow"><p>After creating a new branch and switching to it, we bump the version number. Here, <code>bump-version.sh</code> is a fictional shell script that changes some files in the working copy to reflect the new version. (This can of course be a manual change—the point being that <em>some</em> files change.) Then, the bumped version number is committed.</p><p>This new branch may exist there for a while, until the release may be rolled out definitely. During that time, bug fixes may be applied in this branch (rather than on the <code>develop</code>branch). Adding large new features here is strictly prohibited. They must be merged into <code>develop</code>, and therefore, wait for the next big release.</p></div><div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow"><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">$ ./bump-version.sh 1.2<br> $ git commit -a -m "Version 1.2"</pre></div></div><h4 class="wp-block-heading" id="finishing-a-release-branch"><span id="Finishing_a_release_branchnbsp"> Finishing a release branch </span></h4><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">$ git checkout master $ git merge --no-ff release-1.2 $ git tag -a 1.2 $ git checkout develop $ git merge --no-ff release-1.2 $ git branch -d release-1.2</pre><div class="wp-block-columns has-2-columns is-layout-flex wp-container-core-columns-is-layout-8 wp-block-columns-is-layout-flex"><div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow"><p>When the state of the release branch is ready to become a real release, some actions need to be carried out.</p><p>First, the release branch is merged into <code>master</code> (since every commit on <code>master</code> is a new release <em>by definition</em>, remember).</p><p>Next, that commit on <code>master</code> must be tagged for easy future reference to this historical version.</p><p>Finally, the changes made on the release branch need to be merged back into <code>develop</code>, so that future releases also contain these bug fixes.</p></div><div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow"><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">$ git checkout master $ git merge --no-ff release-1.2 $ git tag -a 1.2</pre></div></div><div class="wp-block-columns has-2-columns is-layout-flex wp-container-core-columns-is-layout-9 wp-block-columns-is-layout-flex"><div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow"><p>The release is now done, and tagged for future reference.</p><p>To keep the changes made in the release branch, we need to merge those back into <code>develop</code>, though. In Git:</p></div><div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow"><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">$ git checkout develop $ git merge --no-ff release-1.2</pre></div></div><div class="wp-block-columns has-2-columns is-layout-flex wp-container-core-columns-is-layout-10 wp-block-columns-is-layout-flex"><div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow"><p>This step may well lead to a merge conflict (probably even, since we have changed the version number). If so, fix it and commit.</p><p>Now we are really done and the release branch may be removed, since we don’t need it anymore:</p></div><div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow"><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">$ git branch -d release-1.2</pre></div></div><h3 class="wp-block-heading" id="feature"><span id="Feature">Feature</span></h3><figure class="wp-block-image"><img decoding="async" src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%201%201'%3E%3C/svg%3E" data-src="http://blog.via-internet.de/wp-content/uploads/2019/03/fb@2x-e1554287024987-700x261.png" alt="" class="wp-image-4387 lazy"></figure><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">$ git checkout -b myfeature develop $ .. do changes... $ git checkout develop $ git merge --no-ff myfeature $ git branch -d myfeature $ git push origin develop</pre><div class="wp-block-columns has-2-columns is-layout-flex wp-container-core-columns-is-layout-11 wp-block-columns-is-layout-flex"><div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow"><h4 class="wp-block-heading" id="creating-a-feature-branch"><span id="Creating_a_feature_branchnbsp">Creating a feature branch </span></h4><p>When starting work on a new feature, branch off from the <code>develop</code> branch.</p><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">$ git checkout -b myfeature develop Switched to a new branch "myfeature" </pre><h4 class="wp-block-heading" id="incorporating-a-finished-feature-on-develop"><span id="Incorporating_a_finished_feature_on_developnbsp">Incorporating a finished feature on develop </span></h4><p>Finished features may be merged into the <code>develop</code> branch to definitely add them to the upcoming release:</p><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">$ git checkout develop< $ git merge --no-ff myfeature $ git branch -d myfeature $ git push origin develop </pre></div><div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow"></div></div><div class="wp-block-columns has-2-columns is-layout-flex wp-container-core-columns-is-layout-12 wp-block-columns-is-layout-flex"><div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow"><p> The <code>--no-ff</code> flag causes the merge to always create a new commit object, even if the merge could be performed with a fast-forward. This avoids losing information about the historical existence of a feature branch and groups together all commits that together added the feature.</p><p>In the latter case, it is impossible to see from the Git history which of the commit objects together have implemented a feature—you would have to manually read all the log messages. Reverting a whole feature (i.e. a group of commits), is a true headache in the latter situation, whereas it is easily done if the <code>--no-ff</code> flag was used.</p></div><div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow"><figure class="wp-block-image"><img class="lazy" decoding="async" src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%201%201'%3E%3C/svg%3E" data-src="https://nvie.com/img/merge-without-ff@2x.png" alt=""></figure></div></div><h2 class="wp-block-heading" id="hotfix"><span id="Hotfix">Hotfix</span></h2><figure class="wp-block-image"><img decoding="async" src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%201%201'%3E%3C/svg%3E" data-src="http://blog.via-internet.de/wp-content/uploads/2019/03/hotfix-branches@2x-e1554287153961-700x519.png" alt="" class="wp-image-4394 lazy"></figure><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">$ git checkout -b hotfix-1.2.1 master $ ... do changes ... $ git commit -a -m "Hotfix Version 1.2.1" $ .. fix bug $ git commit -m "Fixed severe production problem" $ git checkout master $ git merge --no-ff hotfix-1.2.1 $ git tag -a 1.2.1 # incude hotfix into develop $ git checkout develop $ git merge --no-ff hotfix-1.2.1 # finally, remove hotfix branch $ git branch -d hotfix-1.2.1</pre><h2 class="wp-block-heading" id="troubleshooting"><span id="Troubleshooting">Troubleshooting</span></h2><h4 class="wp-block-heading" id="debugging-github-errors"><span id="Debugging_Github_Errors">Debugging Github Errors</span></h4><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">export GIT_TRACE_PACKET=1 export GIT_TRACE=1 export GIT_CURL_VERBOSE=1</pre><h4 class="wp-block-heading" id="error-message-your-local-changes-to-the-following-files-would-be-overwritten-by-merge"><span id="Error_Message_Your_local_changes_to_the_following_files_would_be_overwritten_by_merge">Error Message: Your local changes to the following files would be overwritten by merge: </span></h4><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">error: Your local changes to the following files would be overwritten by merge:<br> README.md<br> Please commit your changes or stash them before you merge.</pre><h4 class="wp-block-heading" id="solution"><span id="Solution">Solution:</span></h4><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">$ git fetch origin master $ git diff origin/master -- [local-path]</pre><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">$ git add [local-path] $ gt commit -m "change: in file [local-path]"</pre><h4 class="wp-block-heading" id="fatal-sha1-file-stdout-write-error-broken-pipe"><span id="fatal_sha1_file_8216ltstdoutgt8217_write_error_Broken_Pipe">fatal: sha1 file ‘<stdout>’ write error: Broken Pipe </span></h4><p>When using ssh to connect to the repositoriy, sometime, you got a timeout if you push to many files or if the files are to big</p><h4 class="wp-block-heading" id="one-possible-solution"><span id="One_possible_Solution">One possible Solution</span></h4><p>Configure ssh to use the following value</p><pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">~/.ssh/config</pre><pre class="EnlighterJSRAW" data-enlighter-language="ini" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">Host * ServerAliveInterval 30 ServerAliveCountMax 4</pre><h4 class="wp-block-heading" id="git-clone-file-name-to-long-on-windows"><span id="git_clone_file_name_to_long_on_windows">git clone: file name to long on windows</span></h4><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">git config --system core.longpaths true</pre><h4 class="wp-block-heading" id="git-config-global-user-email-some-email-com-throws-error-only-one-config-file-at-a-time"><span id="git_config_8211global_useremail_someemailcom_throws_error_only_one_config_file_at_a_time">git config –global user.email “some@email.com” throws “error: only one config file at a time.</span></h4><p>Try to unset GIT_CONFIG and then list your global config with</p><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">unset GIT_CONFIG git config --global --list</pre><p>Other Links</p><p><a href="https://medium.com/flawless-app-stories/useful-git-commands-for-everyday-use-e1a4de64037d">Useful Git commands for everyday use</a></p><p><a href="https://medium.com/android-bits/10-useful-git-commands-you-always-need-b0d0a50b81e6">10 useful Git commands you always need</a></p><p><a href="https://orga.cat/posts/most-useful-git-commands">Most useful Git commands</a></p><p><a href="https://artandlogic.com/2014/01/git-cheat-sheet/">Git Cheat Sheet</a></p><p><a href="https://dzone.com/articles/useful-git-commands">Useful Git commands</a></p><h2 class="wp-block-heading" id="using-local-filesystem-as-respository-master"><span id="Using_local_Filesystem_as_Respository-Master">Using local Filesystem as Respository-Master</span></h2><h4 class="wp-block-heading" id="preparation"><span id="Preparation">Preparation</span></h4><p>Set environment variables for easy typing</p><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">$ REPOS=$HOME/repos</pre><h4 class="wp-block-heading" id="create-repository"><span id="Create_Repository">Create Repository</span></h4><pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">$ mkdir $REPOS $ cd $REPOS</pre><pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">$ git init --bare src</pre><h4 class="wp-block-heading" id="create-src-folder"><span id="Create_src_folder">Create src folder</span></h4><pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">$ mkdir $HOME/entw $ cd $HOME/entw $ mkdir src $ cd src $ git init</pre><h4 class="wp-block-heading" id="create-some-content"><span id="Create_some_content">Create some content</span></h4><pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">$ touch README.md</pre><pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">$ git add -A</pre><pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">$ git commit -m "initial commit"</pre><pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">$ git remote add origin $REPOS/src $ git remote -v $ git push --set-upstream origin master $ git push origin master</pre><h4 class="wp-block-heading" id="create-clone"><span id="Create_clone">Create clone</span></h4><pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">$ mkdir $HOME/test $ cd $HOME/test</pre><pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">$ git clone $HOME/repos/src</pre><pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">$ cd src $ ls -al total 0 drwxr-xr-x 4 user wheel 128 19 Mär 18:48 . drwxr-xr-x 3 user wheel 96 19 Mär 18:48 .. drwxr-xr-x 12 user wheel 384 19 Mär 18:48 .git -rw-r--r-- 1 user wheel 0 19 Mär 18:48 README.md</pre><p>You will notice, that the file README.md is empty. Because it was ony created with touch.</p><h4 class="wp-block-heading" id="add-some-content-to-source-repository"><span id="Add_some_content_to_source_repository">Add some content to source repository</span></h4><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">$ cd $HOME/entw/src $ echo "# This is the README.md from ENTW" >README.md $ touch git_update $ touch git_push</pre><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">$ ls -al total 16 drwxr-xr-x 6 user wheel 192 19 Mär 18:53 . drwxr-xr-x 3 user wheel 96 19 Mär 18:43 .. drwxr-xr-x 12 user wheel 384 19 Mär 18:47 .git -rw-r--r-- 1 user wheel 34 19 Mär 18:52 README.md -rw-r--r-- 1 user wheel 0 19 Mär 18:53 git_push -rw-r--r-- 1 user wheel 0 19 Mär 18:53 git_update</pre><h4 class="wp-block-heading" id="add-changes-to-repository"><span id="Add_changes_to_repository">Add changes to repository</span></h4><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">$ git add -A $ git commit -m "-" [master 106b27a] - 3 files changed, 1 insertion(+) create mode 100644 git_push create mode 100644 git_update</pre><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">$ git push --set-upstream origin master Objekte aufzählen: 5, Fertig. Zähle Objekte: 100 Delta-Kompression verwendet bis zu 8 Threads. Komprimiere Objekte: 100 Schreibe Objekte: 100 Gesamt 3 (Delta 0), Wiederverwendet 0 (Delta 0) To ..../repos/src 7ed6d3b..106b27a master -> master Branch 'master' folgt nun Remote-Branch 'master' von 'origin'.</pre><h4 class="wp-block-heading" id="update-clone"><span id="Update_clone">Update clone</span></h4><pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">$ cd $OME/test/src $ git pull # git fetch # This updates 'remote' portion of local repo. # git reset --hard origin/<your-working-branch> remote: Objekte aufzählen: 5, Fertig. remote: Zähle Objekte: 100 remote: Komprimiere Objekte: 100 remote: Gesamt 3 (Delta 0), Wiederverwendet 0 (Delta 0) Entpacke Objekte: 100 Von .../repos/src 7ed6d3b..106b27a master -> origin/master</pre><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">$ git merge origin/master Aktualisiere 7ed6d3b..106b27a Fast-forward README.md | 1 + git_push | 0 git_update | 0 3 files changed, 1 insertion(+) create mode 100644 git_push create mode 100644 git_update</pre><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">$ ls -al total 16 drwxr-xr-x 6 user wheel 192 19 Mär 19:02 . drwxr-xr-x 3 user wheel 96 19 Mär 18:48 .. drwxr-xr-x 14 user wheel 448 19 Mär 19:02 .git -rw-r--r-- 1 user wheel 34 19 Mär 19:02 README.md -rw-r--r-- 1 user wheel 0 19 Mär 19:02 git_push -rw-r--r-- 1 user wheel 0 19 Mär 19:02 git_update</pre><h2 class="wp-block-heading" id="todo"><span id="TODO">TODO</span></h2><h4 class="wp-block-heading" id="see-changes-before-pulling-from-remote-git-repositoryf"><span id="See_changes_before_pulling_from_remote_git_repositoryf">See changes before pulling from remote git repository<a href="https://gist.github.com/jtdp/5443297#file-gistfile1-sh"><strong>f</strong></a></span></h4><figure class="wp-block-table"><table><tbody><tr><td># fetch the changes from the remote</td></tr><tr><td>git fetch origin</td></tr><tr></tr><tr><td># show commit logs of changes</td></tr><tr><td>git log master..origin/master</td></tr><tr></tr><tr><td># show diffs of changes</td></tr><tr><td>git diff master..origin/master</td></tr><tr></tr><tr><td># apply the changes by merge..</td></tr><tr><td>git merge origin/master</td></tr><tr></tr><tr><td># .. or just pull the changes</td></tr><tr><td>git pull</td></tr></tbody></table></figure><h4 class="wp-block-heading" id="you-want-to-push-your-local-files-to-remote-files"><span id="You_want_to_push_your_local_files_to_remote_files">You want to push your local files to remote files</span></h4><pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">git push -f <remote> <branch></pre><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">git push -f origin master</pre><h3 class="wp-block-heading" id="configure-hooks"><span id="Configure_Hooks">Configure Hooks</span></h3><pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">git config --global core.hooksPath .githooks mkdir .githooks cp .git/hooks/* .githooks</pre><h4 class="wp-block-heading" id="prepare-commit"><span id="commit-msg">commit-msg</span></h4><pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">#!/bin/sh # NAME=$(git rev-parse --abbrev-ref HEAD) DESCRIPTION=$(git config branch."$NAME".description) echo "$NAME"': '$(cat "$1") > "$1" if [ -n "$DESCRIPTION" ] then echo "" >> "$1" echo $DESCRIPTION >> "$1" fi</pre><h4 class="wp-block-heading" id="prepare-commit"><span id="prepare-commit">prepare-commit</span></h4><pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">#!/bin/sh # COMMIT_MSG_FILE=$1 COMMIT_SOURCE=$2 SHA1=$3 branchPath=$(git symbolic-ref -q HEAD) branchName=${branchPath##*/} if [ -n "$branchName" ]; then echo "$branchName | $(cat $1)" > $1 fi</pre><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">file=$(git config hooks.versionfilename) if [[ -z $file ]] then file=".version" fi # Version number echo "$(git rev-parse --abbrev-ref HEAD): $(git describe --tags --long)" >$file exec git add $file</pre><h4 class="wp-block-heading" id="pre-commit"><span id="pre-commit">pre-commit</span></h4><pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">#!/bin/sh _BRANCHPATH=$(git symbolic-ref -q HEAD) _BRANCHNAME=${_BRANCHPATH##*/} _TIMESTAMP="$(date '+ echo "HOOK : $0" echo "PARAMETER : '$*''" echo "BRANCHPATH: $_BRANCHPATH" echo "BRANCHNAME: $_BRANCHNAME" LOG() { [[ "$GIT_COMMIT_DETAILED_LOGGING" == "YES" ]] && echo "LOG: $*" } REPLACE() { local _TYP; _TYP="$1"; shift local _TAG; _TAG="$1"; shift local _WITH; _WITH="$1"; shift local _FILE; _FILE="$1"; shift case "$_TYP" in PYTHON) perl -pi -e 's/(\s*)(__DEPLOY_'${_TAG}'\s*=\s*)(".+")/${1}${2}"'"${_WITH}"'"/' "${_FILE}" ;; *) LOG "Undefined typ '$TYP' for file $_FILE" ;; esac rm -f "${_FILE}.bak" } LOG "working on branch $_BRANCH" for _FILE in $(git diff-index --name-status --cached HEAD | grep -v ^D | cut -c3-) do LOG "checking: $_FILE" # Only examine known text files if [[ "$_FILE" =~ [.](py)$ ]]; then LOG "patching: $_FILE" REPLACE PYTHON TAG "$_BRANCHNAME" "$_FILE" REPLACE PYTHON TIMESTAMP "$_TIMESTAMP" "$_FILE" fi done </pre><h2 class="wp-block-heading" id="get-information"><span id="Get_Information">Get Information</span></h2><figure class="wp-block-table"><table><tbody><tr><td>git rev-parse –abbrev-ref HEAD</td><td>get branch name</td><td>feature/add-new-content</td></tr><tr><td>git symbolic-ref -q HEAD</td><td></td><td>refs/heads/<meta charset="utf-8">feature/add-new-content</td></tr><tr><td><meta charset="utf-8">git rev-parse –show-toplevel</td><td><meta charset="utf-8">show current path of git repository</td><td></td></tr><tr><td></td><td></td><td></td></tr><tr><td></td><td></td><td></td></tr></tbody></table></figure><h2 class="wp-block-heading" id="config"><span id="Config">Config</span></h2><h3 class="wp-block-heading" id="change-github-repository-for-local-clone"><span id="Change_Github_repository_for_local_clone">Change Github repository for local clone</span></h3><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">cd <original repository> git remote set-url origin https://github.com/<new git user>/<new project name> git push -u origin master </pre><h3 class="wp-block-heading" id="cr-lf-mapping"><span id="CRLF_Mapping">CR/LF Mapping</span></h3><pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">git config core.autocrlf true git config --global core.safecrlf false</pre><h2 class="wp-block-heading" id="create-release"><span id="Create_Release">Create Release</span></h2><pre class="EnlighterJSRAW" data-enlighter-language="shell" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">#!/bin/bash if [ $# -ne 1 ]; then echo "Syntax: release [VERSION]" exit 1 fi VERSION=$1 # Create release git flow release start $VERSION || exit 1 GIT_MERGE_AUTOEDIT=no git flow release finish -m $VERSION $VERSION # Publish release git push origin HEAD --tags # Merge release into develop git checkout develop git merge master</pre>
git ls-files -z | xargs -0 -n1 -I{} -- git log -1 --format="



Git Configuration

Show location of configuration files

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
git config --list --show-origin
git config --list --show-origin
git config --list --show-origin

This dows not work, if you have set the environment var GIT_CONFIG. In this case, do

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
unset GIT_CONFIG
git config --global --list
unset GIT_CONFIG git config --global --list
unset GIT_CONFIG
git config --global --list

Edit config files

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
git config --edit --global
git config --edit --global
git config --edit --global
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
git config --edit --system
git config --edit --system
git config --edit --system
DESCRIPTIONGIT COMMAND
Configure the author name to be used with your commits.git config --global user.name "XXX"
Configure the author email address to be used with your commitsgit config --global user.email xxx@example.com
Will remove user credential details from the repositorygit config --local credential.helper ""
git config —show-origin
List all currently configured remote repository URLsgit remote -v
If you haven’t connected your local repository to a remote server, To add a remote server to a local repositorygit remote add origin <repo_url>

Git Commit and Push

DESCRIPTIONGIT COMMAND
Create a file name README.md with Readme content contentecho "Readme content" >> README.md
List the files you’ve changed and those you still need to add or commitgit status
Add all or one file to staginggit add . OR git add file_name
Commit changes to head with messagegit commit -m 'message'
Commit any files you’ve added with git add, and also commit any files you’ve changed since thengit commit -a
Send all commits from local repository to remote repositorygit push
Do a git push and sets the default remote branch for the current local branch. So any future git pull command will attempt to bring in commits from the <remote-branch>into the current local branchgit push -u <remote-branch>
Send changes to the master branch of your remote repositorygit push origin master
Push a specific branch to your remote repositorygit push origin <branch_name>
Push all branches to your remote repositorygit push --all origin

Working with the Git Workflow

The following steps are based on a branching model, described here.

Name Beschreibung
master
hotfixes
release
develop
feature

Working with branches

Create branch ‘develop’

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
$ git clone git@github.com:<USER>/<REPO>.git develop
$ cd develop
$ git checkout -b develop
$ git push --set-upstream origin develop
$ git clone git@github.com:<USER>/<REPO>.git develop $ cd develop $ git checkout -b develop $ git push --set-upstream origin develop
$ git clone git@github.com:<USER>/<REPO>.git develop
$ cd develop
$ git checkout -b develop
$ git push --set-upstream origin develop

Create branch ‘feature-xxx’

We dont’t want do clone the whole repository, but only the files needed for the feature

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
$ git clone -b develop -n --depth 1 git@github.com:<USER>/<REPO>.git feature-2.2.0
$ cd feature-2.2.0
$ git clone -b develop -n --depth 1 git@github.com:<USER>/<REPO>.git feature-2.2.0 $ cd feature-2.2.0
$ git clone -b develop -n --depth 1 git@github.com:<USER>/<REPO>.git feature-2.2.0
$ cd feature-2.2.0

Branch löschen

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
$ git push origin -delete hotfix-1.2.1-compress-data
$ git push origin -delete hotfix-1.2.1-compress-data
$ git push origin -delete hotfix-1.2.1-compress-data

Workflow – Cheatsheet

Working with branches

How to rename git local and remote branches

Check out branch with old name

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
git checkout feature-2.1.2
git checkout feature-2.1.2
git checkout feature-2.1.2

Rename branch

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
git branch -m feature-2.01.02
git branch -m feature-2.01.02
git branch -m feature-2.01.02

Checkin branch with new name

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
git push origin :feature-2.1.2 feature-2.01.02
git push origin :feature-2.1.2 feature-2.01.02
git push origin :feature-2.1.2 feature-2.01.02

1. Rename your local branch.

If you have named a branch incorrectly AND pushed this to the remote repository follow these steps before any other developers get a chance to jump on you and give you shit for not correctly following naming conventions.

If you are on the branch you want to rename:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
git branch -m new-name
git branch -m new-name
git branch -m new-name

If you are on a different branch:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
git branch -m old-name new-name
git branch -m old-name new-name
git branch -m old-name new-name

2. Delete the old-name remote branch and push the new-name local branch.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
git push origin :old-name new-name
git push origin :old-name new-name
git push origin :old-name new-name

3. Reset the upstream branch for the new-name local branch.Switch to the branch and then:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
git push origin -u new-name
git push origin -u new-name
git push origin -u new-name

Or you as a fast way to do that, you can use these 3 steps: command in your terminal

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
git branch -m old_branch new_branch # Rename branch locally
git push origin :old_branch # Delete old branch
git push --set-upstream origin new_branch # Push new branch, set local branch to track new remote
git branch -m old_branch new_branch # Rename branch locally git push origin :old_branch # Delete old branch git push --set-upstream origin new_branch # Push new branch, set local branch to track new remote
git branch -m old_branch new_branch         # Rename branch locally    
git push origin :old_branch                 # Delete old branch    
git push --set-upstream origin new_branch   # Push new branch, set local branch to track new remote
Neues Feature erstellen
Repository clonen$ git checkout -b feature-1.2.2 develop
Änderungen durchführen
Änderungen einchecken$ git checkout develop
$ git merge –no-ff feature-1.2.2
$ git branch -d feature-1.2.2
$ git push origin develop
Neuen Hotfix erstelllen
Repository auschecken$ git checkout -b hotfix-1.2.1 master
Änderungen durchführen
Änderungen einchecken$ git commit -a -m “hotfix: hotfix-1.2.1| compress mart”
Hotfix beenden$ git checkout master
$ git merge –no-ff hotfix-1.2.1
$ git tag -a 1.2.1
Hotfix in Master einchecken$ git checkout develop
$ git merge –no-ff hotfix-1.2.1  
Hotfix Branch entfernen$ git branch -d hotfix-1.2.1
Neues Release erstellen:
Repository clonen$ git checkout -b release-1.2 develop
Änderungen durchführen
Änderungen einchecken$ git commit -a -m “release: changes for release 1.2”
Release beenden$ git checkout master
$ git merge –no-ff release-1.2
$ git tag -a 1.2

Git Flow

Initialize

Start using git-flow by initializing it inside an existing git repository:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
$ git flow init
$ git flow init
$ git flow init

Start a new feature

Development of new features starting from the ‘develop’ branch.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
git flow feature start MYFEATURE
git flow feature start MYFEATURE
git flow feature start MYFEATURE

Finish up a feature

Finish the development of a feature. This action performs the following

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
git flow feature finish MYFEATURE
git flow feature finish MYFEATURE
git flow feature finish MYFEATURE

Publish a feature

Publish a feature to the remote server so it can be used by other users.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
git flow feature publish MYFEATURE
git flow feature publish MYFEATURE
git flow feature publish MYFEATURE

Getting a published feature

Get a feature published by another user.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
git flow feature pull origin MYFEATURE
git flow feature pull origin MYFEATURE
git flow feature pull origin MYFEATURE

You can track a feature on origin by using

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
git flow feature track MYFEATURE
git flow feature track MYFEATURE
git flow feature track MYFEATURE

Start a release

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
git flow release start RELEASE [BASE]
git flow release start RELEASE [BASE]
git flow release start RELEASE [BASE]

It’s wise to publish the release branch after creating it to allow release commits by other developers. Do it similar to feature publishing with the command:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
git flow release publish RELEASE
git flow release publish RELEASE
git flow release publish RELEASE

(You can track a remote release with the 
git flow release track RELEASEcommand)

Finish up a release

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
git flow release finish RELEASE
git flow release finish RELEASE
git flow release finish RELEASE

Don’t forget to push your tags with git push origin --tags

Hotfixes

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
git flow hotfix start VERSION [BASENAME]
git flow hotfix start VERSION [BASENAME]
git flow hotfix start VERSION [BASENAME]

Finish a hotfix

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
git flow hotfix finish VERSION
git flow hotfix finish VERSION
git flow hotfix finish VERSION

Usefull commands

basic commandsdescription
git init
git status  [ -s ]status of files and local repo
git ls-filesshow files which are tracked by git
git log [ –oneline ]
git log [–oneline –graph –decorate –all]
shows commit history
git add <changed file>
git add .git add -u
add single file to indexadd all files from the workspace to indexstage current workspace into index to cleanup inconsistencies
git commit [ -m ‘message’ ]commit into local repo only
git push -u origin masterpush the repo from local to remote repo
git help [option]get help page for specific options
git config –global alias.bla “command”
git bla [– <filename>]
set alias bla to a specific commandexec alias (for specific file)
git mv fileA fileB
git commit -m “…..”
rename fileA to fileBand commit
git rm fileC
git commit -m “…..”
delete fileCand commit
advanced commandsdescription
git reset HEAD <filename>undo changes from index back to workspace
git checkout <filename>
git checkout master
git checkout <branchname>
checkout single file from local repo to workspacecheckout/switch to the master branchcheckout/switch to another branch
git checkout -b <new branchname>
git branch <new branchname>
create new branch and switch to it immediatelycreate new branch in the background, doesn’t switch to it
git branchshows all available branches
git diff
git difftool
show differences of local and committed file
shows diff in vimdiff
git merge <other branch>
git mergetool
merge other branch into master (current branch)manage the different files in vimdiff
git branch -d <branchname>delete branch (does NOT include merge)
git branch -m <new name>rename a
$ git diff master..developmentcompare two branches
git tag <mytag>
git tag -a v1.0 -m “description”
git show v1.0
add an additional label/tag to a branchannotation tag with release informationshows details of tag v1.0
git stash
git reset <ID> [–soft | –mixed | –hard]
git reflog ….
git fetch ….update local repo with changes from remote repo. (non destructive)
git pull …update local repo with changes from remote repo. it does effectively a fetch and merge in one command
git clone https://<username>:<token>@github.com/<organisation-space>/<repository>
download the remote repo into local workspace
git remote -v
git remote show origin
shows url of remote reposhows detail infos of a remote repo
.gitignorecontains filename to exclude from git

Git Workflow

Release

Creating a release branch

Release branches are created from the develop branch. For example, say version 1.1.5 is the current production release and we have a big release coming up. The state of developis ready for the “next release” and we have decided that this will become version 1.2 (rather than 1.1.6 or 2.0). So we branch off and give the release branch a name reflecting the new version number:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
$ git checkout -b release-1.2 develop
$ git checkout -b release-1.2 develop
$ git checkout -b release-1.2 develop

After creating a new branch and switching to it, we bump the version number. Here, bump-version.sh is a fictional shell script that changes some files in the working copy to reflect the new version. (This can of course be a manual change—the point being that some files change.) Then, the bumped version number is committed.

This new branch may exist there for a while, until the release may be rolled out definitely. During that time, bug fixes may be applied in this branch (rather than on the developbranch). Adding large new features here is strictly prohibited. They must be merged into develop, and therefore, wait for the next big release.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
$ ./bump-version.sh 1.2<br>
$ git commit -a -m "Version 1.2"
$ ./bump-version.sh 1.2<br> $ git commit -a -m "Version 1.2"
$ ./bump-version.sh 1.2<br>
$ git commit -a -m "Version 1.2"

Finishing a release branch 

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
$ git checkout master
$ git merge --no-ff release-1.2
$ git tag -a 1.2
$ git checkout develop
$ git merge --no-ff release-1.2
$ git branch -d release-1.2
$ git checkout master $ git merge --no-ff release-1.2 $ git tag -a 1.2 $ git checkout develop $ git merge --no-ff release-1.2 $ git branch -d release-1.2
$ git checkout master
$ git merge --no-ff release-1.2
$ git tag -a 1.2
$ git checkout develop
$ git merge --no-ff release-1.2
$ git branch -d release-1.2

When the state of the release branch is ready to become a real release, some actions need to be carried out.

First, the release branch is merged into master (since every commit on master is a new release by definition, remember).

Next, that commit on master must be tagged for easy future reference to this historical version.

Finally, the changes made on the release branch need to be merged back into develop, so that future releases also contain these bug fixes.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
$ git checkout master
$ git merge --no-ff release-1.2
$ git tag -a 1.2
$ git checkout master $ git merge --no-ff release-1.2 $ git tag -a 1.2
$ git checkout master
$ git merge --no-ff release-1.2
$ git tag -a 1.2

The release is now done, and tagged for future reference.

To keep the changes made in the release branch, we need to merge those back into develop, though. In Git:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
$ git checkout develop
$ git merge --no-ff release-1.2
$ git checkout develop $ git merge --no-ff release-1.2
$ git checkout develop
$ git merge --no-ff release-1.2

This step may well lead to a merge conflict (probably even, since we have changed the version number). If so, fix it and commit.

Now we are really done and the release branch may be removed, since we don’t need it anymore:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
$ git branch -d release-1.2
$ git branch -d release-1.2
$ git branch -d release-1.2

Feature

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
$ git checkout -b myfeature develop
$ .. do changes...
$ git checkout develop
$ git merge --no-ff myfeature
$ git branch -d myfeature
$ git push origin develop
$ git checkout -b myfeature develop $ .. do changes... $ git checkout develop $ git merge --no-ff myfeature $ git branch -d myfeature $ git push origin develop
$ git checkout -b myfeature develop
$ .. do changes...

$ git checkout develop
$ git merge --no-ff myfeature
$ git branch -d myfeature
$ git push origin develop

Creating a feature branch 

When starting work on a new feature, branch off from the develop branch.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
$ git checkout -b myfeature develop
Switched to a new branch "myfeature"
$ git checkout -b myfeature develop Switched to a new branch "myfeature"
$ git checkout -b myfeature develop
Switched to a new branch "myfeature"

Incorporating a finished feature on develop 

Finished features may be merged into the develop branch to definitely add them to the upcoming release:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
$ git checkout develop<
$ git merge --no-ff myfeature
$ git branch -d myfeature
$ git push origin develop
$ git checkout develop< $ git merge --no-ff myfeature $ git branch -d myfeature $ git push origin develop
$ git checkout develop<
$ git merge --no-ff myfeature
$ git branch -d myfeature
$ git push origin develop 

The --no-ff flag causes the merge to always create a new commit object, even if the merge could be performed with a fast-forward. This avoids losing information about the historical existence of a feature branch and groups together all commits that together added the feature.

In the latter case, it is impossible to see from the Git history which of the commit objects together have implemented a feature—you would have to manually read all the log messages. Reverting a whole feature (i.e. a group of commits), is a true headache in the latter situation, whereas it is easily done if the --no-ff flag was used.

Hotfix

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
$ git checkout -b hotfix-1.2.1 master
$ ... do changes ...
$ git commit -a -m "Hotfix Version 1.2.1"
$ .. fix bug
$ git commit -m "Fixed severe production problem"
$ git checkout master
$ git merge --no-ff hotfix-1.2.1
$ git tag -a 1.2.1
# incude hotfix into develop
$ git checkout develop
$ git merge --no-ff hotfix-1.2.1
# finally, remove hotfix branch
$ git branch -d hotfix-1.2.1
$ git checkout -b hotfix-1.2.1 master $ ... do changes ... $ git commit -a -m "Hotfix Version 1.2.1" $ .. fix bug $ git commit -m "Fixed severe production problem" $ git checkout master $ git merge --no-ff hotfix-1.2.1 $ git tag -a 1.2.1 # incude hotfix into develop $ git checkout develop $ git merge --no-ff hotfix-1.2.1 # finally, remove hotfix branch $ git branch -d hotfix-1.2.1
$ git checkout -b hotfix-1.2.1 master
$ ... do changes ... 
$ git commit -a -m "Hotfix Version 1.2.1"
$ .. fix bug
$ git commit -m "Fixed severe production problem"

$ git checkout master
$ git merge --no-ff hotfix-1.2.1
$ git tag -a 1.2.1

# incude hotfix into develop
$ git checkout develop
$ git merge --no-ff hotfix-1.2.1

# finally, remove hotfix branch
$ git branch -d hotfix-1.2.1

Troubleshooting

Debugging Github Errors

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
export GIT_TRACE_PACKET=1
export GIT_TRACE=1
export GIT_CURL_VERBOSE=1
export GIT_TRACE_PACKET=1 export GIT_TRACE=1 export GIT_CURL_VERBOSE=1
export GIT_TRACE_PACKET=1
export GIT_TRACE=1
export GIT_CURL_VERBOSE=1

Error Message: Your local changes to the following files would be overwritten by merge:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
error: Your local changes to the following files would be overwritten by merge:<br>
README.md<br>
Please commit your changes or stash them before you merge.
error: Your local changes to the following files would be overwritten by merge:<br> README.md<br> Please commit your changes or stash them before you merge.
error: Your local changes to the following files would be overwritten by merge:<br>
        README.md<br>
Please commit your changes or stash them before you merge.

Solution:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
$ git fetch origin master
$ git diff origin/master -- [local-path]
$ git fetch origin master $ git diff origin/master -- [local-path]
$ git fetch origin master
$ git diff origin/master -- [local-path]
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
$ git add [local-path]
$ gt commit -m "change: in file [local-path]"
$ git add [local-path] $ gt commit -m "change: in file [local-path]"
$ git add [local-path]
$ gt commit -m "change: in file [local-path]"

fatal: sha1 file ‘<stdout>’ write error: Broken Pipe

When using ssh to connect to the repositoriy, sometime, you got a timeout if you push to many files or if the files are to big

One possible Solution

Configure ssh to use the following value

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
~/.ssh/config
~/.ssh/config
~/.ssh/config
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
Host *
ServerAliveInterval 30
ServerAliveCountMax 4
Host * ServerAliveInterval 30 ServerAliveCountMax 4
Host *
     ServerAliveInterval 30
     ServerAliveCountMax 4

git clone: file name to long on windows

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
git config --system core.longpaths true
git config --system core.longpaths true
git config --system core.longpaths true

git config –global user.email “some@email.com” throws “error: only one config file at a time.

Try to unset GIT_CONFIG and then list your global config with

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
unset GIT_CONFIG
git config --global --list
unset GIT_CONFIG git config --global --list
unset GIT_CONFIG
git config --global --list

Other Links

Useful Git commands for everyday use

10 useful Git commands you always need

Most useful Git commands

Git Cheat Sheet

Useful Git commands

Using local Filesystem as Respository-Master

Preparation

Set environment variables for easy typing

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
$ REPOS=$HOME/repos
$ REPOS=$HOME/repos
$ REPOS=$HOME/repos

Create Repository

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
$ mkdir $REPOS
$ cd $REPOS
$ mkdir $REPOS $ cd $REPOS
$ mkdir $REPOS
$ cd    $REPOS
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
$ git init --bare src
$ git init --bare src
$ git init --bare src

Create src folder

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
$ mkdir $HOME/entw
$ cd $HOME/entw
$ mkdir src
$ cd src
$ git init
$ mkdir $HOME/entw $ cd $HOME/entw $ mkdir src $ cd src $ git init
$ mkdir $HOME/entw
$ cd    $HOME/entw
$ mkdir src
$ cd    src
$ git init

Create some content

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
$ touch README.md
$ touch README.md
$ touch README.md
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
$ git add -A
$ git add -A
$ git add -A
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
$ git commit -m "initial commit"
$ git commit -m "initial commit"
$ git commit -m "initial commit"
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
$ git remote add origin $REPOS/src
$ git remote -v
$ git push --set-upstream origin master
$ git push origin master
$ git remote add origin $REPOS/src $ git remote -v $ git push --set-upstream origin master $ git push origin master
$ git remote add origin $REPOS/src
$ git remote -v
$ git push --set-upstream origin master
$ git push origin master

Create clone

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
$ mkdir $HOME/test
$ cd $HOME/test
$ mkdir $HOME/test $ cd $HOME/test
$ mkdir $HOME/test
$ cd    $HOME/test
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
$ git clone $HOME/repos/src
$ git clone $HOME/repos/src
$ git clone $HOME/repos/src
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
$ cd src
$ ls -al
total 0
drwxr-xr-x 4 user wheel 128 19 Mär 18:48 .
drwxr-xr-x 3 user wheel 96 19 Mär 18:48 ..
drwxr-xr-x 12 user wheel 384 19 Mär 18:48 .git
-rw-r--r-- 1 user wheel 0 19 Mär 18:48 README.md
$ cd src $ ls -al total 0 drwxr-xr-x 4 user wheel 128 19 Mär 18:48 . drwxr-xr-x 3 user wheel 96 19 Mär 18:48 .. drwxr-xr-x 12 user wheel 384 19 Mär 18:48 .git -rw-r--r-- 1 user wheel 0 19 Mär 18:48 README.md
$ cd src
$ ls -al
total 0
drwxr-xr-x   4 user  wheel  128 19 Mär 18:48 .
drwxr-xr-x   3 user  wheel   96 19 Mär 18:48 ..
drwxr-xr-x  12 user  wheel  384 19 Mär 18:48 .git
-rw-r--r--   1 user  wheel    0 19 Mär 18:48 README.md

You will notice, that the file README.md is empty. Because it was ony created with touch.

Add some content to source repository

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
$ cd $HOME/entw/src
$ echo "# This is the README.md from ENTW" >README.md
$ touch git_update
$ touch git_push
$ cd $HOME/entw/src $ echo "# This is the README.md from ENTW" >README.md $ touch git_update $ touch git_push
$ cd $HOME/entw/src
$ echo "# This is the README.md from ENTW" >README.md
$ touch git_update
$ touch git_push
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
$ ls -al
total 16
drwxr-xr-x 6 user wheel 192 19 Mär 18:53 .
drwxr-xr-x 3 user wheel 96 19 Mär 18:43 ..
drwxr-xr-x 12 user wheel 384 19 Mär 18:47 .git
-rw-r--r-- 1 user wheel 34 19 Mär 18:52 README.md
-rw-r--r-- 1 user wheel 0 19 Mär 18:53 git_push
-rw-r--r-- 1 user wheel 0 19 Mär 18:53 git_update
$ ls -al total 16 drwxr-xr-x 6 user wheel 192 19 Mär 18:53 . drwxr-xr-x 3 user wheel 96 19 Mär 18:43 .. drwxr-xr-x 12 user wheel 384 19 Mär 18:47 .git -rw-r--r-- 1 user wheel 34 19 Mär 18:52 README.md -rw-r--r-- 1 user wheel 0 19 Mär 18:53 git_push -rw-r--r-- 1 user wheel 0 19 Mär 18:53 git_update
$ ls -al
total 16
drwxr-xr-x   6 user  wheel  192 19 Mär 18:53 .
drwxr-xr-x   3 user  wheel   96 19 Mär 18:43 ..
drwxr-xr-x  12 user  wheel  384 19 Mär 18:47 .git
-rw-r--r--   1 user  wheel   34 19 Mär 18:52 README.md
-rw-r--r--   1 user  wheel    0 19 Mär 18:53 git_push
-rw-r--r--   1 user  wheel    0 19 Mär 18:53 git_update

Add changes to repository

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
$ git add -A
$ git commit -m "-"
[master 106b27a] -
3 files changed, 1 insertion(+)
create mode 100644 git_push
create mode 100644 git_update
$ git add -A $ git commit -m "-" [master 106b27a] - 3 files changed, 1 insertion(+) create mode 100644 git_push create mode 100644 git_update
$ git add -A
$ git commit -m "-"
[master 106b27a] -
 3 files changed, 1 insertion(+)
 create mode 100644 git_push
 create mode 100644 git_update
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
$ git push --set-upstream origin master
Objekte aufzählen: 5, Fertig.
Zähle Objekte: 100
Delta-Kompression verwendet bis zu 8 Threads.
Komprimiere Objekte: 100
Schreibe Objekte: 100
Gesamt 3 (Delta 0), Wiederverwendet 0 (Delta 0)
To ..../repos/src
7ed6d3b..106b27a master -> master
Branch 'master' folgt nun Remote-Branch 'master' von 'origin'.
$ git push --set-upstream origin master Objekte aufzählen: 5, Fertig. Zähle Objekte: 100 Delta-Kompression verwendet bis zu 8 Threads. Komprimiere Objekte: 100 Schreibe Objekte: 100 Gesamt 3 (Delta 0), Wiederverwendet 0 (Delta 0) To ..../repos/src 7ed6d3b..106b27a master -> master Branch 'master' folgt nun Remote-Branch 'master' von 'origin'.
$ git push --set-upstream origin master
Objekte aufzählen: 5, Fertig.
Zähle Objekte: 100
Delta-Kompression verwendet bis zu 8 Threads.
Komprimiere Objekte: 100
Schreibe Objekte: 100
Gesamt 3 (Delta 0), Wiederverwendet 0 (Delta 0)
To ..../repos/src
   7ed6d3b..106b27a  master -> master
Branch 'master' folgt nun Remote-Branch 'master' von 'origin'.

Update clone

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
$ cd $OME/test/src
$ git pull
# git fetch # This updates 'remote' portion of local repo.
# git reset --hard origin/<your-working-branch>
remote: Objekte aufzählen: 5, Fertig.
remote: Zähle Objekte: 100
remote: Komprimiere Objekte: 100
remote: Gesamt 3 (Delta 0), Wiederverwendet 0 (Delta 0)
Entpacke Objekte: 100
Von .../repos/src
7ed6d3b..106b27a master -> origin/master
$ cd $OME/test/src $ git pull # git fetch # This updates 'remote' portion of local repo. # git reset --hard origin/<your-working-branch> remote: Objekte aufzählen: 5, Fertig. remote: Zähle Objekte: 100 remote: Komprimiere Objekte: 100 remote: Gesamt 3 (Delta 0), Wiederverwendet 0 (Delta 0) Entpacke Objekte: 100 Von .../repos/src 7ed6d3b..106b27a master -> origin/master
$ cd $OME/test/src
$ git pull
# git fetch   # This updates 'remote' portion of local repo. 
# git reset --hard origin/<your-working-branch>
remote: Objekte aufzählen: 5, Fertig.
remote: Zähle Objekte: 100
remote: Komprimiere Objekte: 100
remote: Gesamt 3 (Delta 0), Wiederverwendet 0 (Delta 0)
Entpacke Objekte: 100
Von .../repos/src
   7ed6d3b..106b27a  master     -> origin/master
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
$ git merge origin/master
Aktualisiere 7ed6d3b..106b27a
Fast-forward
README.md | 1 +
git_push | 0
git_update | 0
3 files changed, 1 insertion(+)
create mode 100644 git_push
create mode 100644 git_update
$ git merge origin/master Aktualisiere 7ed6d3b..106b27a Fast-forward README.md | 1 + git_push | 0 git_update | 0 3 files changed, 1 insertion(+) create mode 100644 git_push create mode 100644 git_update
$ git merge origin/master
Aktualisiere 7ed6d3b..106b27a
Fast-forward
 README.md  | 1 +
 git_push   | 0
 git_update | 0
 3 files changed, 1 insertion(+)
 create mode 100644 git_push
 create mode 100644 git_update
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
$ ls -al
total 16
drwxr-xr-x 6 user wheel 192 19 Mär 19:02 .
drwxr-xr-x 3 user wheel 96 19 Mär 18:48 ..
drwxr-xr-x 14 user wheel 448 19 Mär 19:02 .git
-rw-r--r-- 1 user wheel 34 19 Mär 19:02 README.md
-rw-r--r-- 1 user wheel 0 19 Mär 19:02 git_push
-rw-r--r-- 1 user wheel 0 19 Mär 19:02 git_update
$ ls -al total 16 drwxr-xr-x 6 user wheel 192 19 Mär 19:02 . drwxr-xr-x 3 user wheel 96 19 Mär 18:48 .. drwxr-xr-x 14 user wheel 448 19 Mär 19:02 .git -rw-r--r-- 1 user wheel 34 19 Mär 19:02 README.md -rw-r--r-- 1 user wheel 0 19 Mär 19:02 git_push -rw-r--r-- 1 user wheel 0 19 Mär 19:02 git_update
$ ls -al
total 16
drwxr-xr-x   6 user  wheel  192 19 Mär 19:02 .
drwxr-xr-x   3 user  wheel   96 19 Mär 18:48 ..
drwxr-xr-x  14 user  wheel  448 19 Mär 19:02 .git
-rw-r--r--   1 user  wheel   34 19 Mär 19:02 README.md
-rw-r--r--   1 user  wheel    0 19 Mär 19:02 git_push
-rw-r--r--   1 user  wheel    0 19 Mär 19:02 git_update

TODO

See changes before pulling from remote git repositoryf

# fetch the changes from the remote
git fetch origin
# show commit logs of changes
git log master..origin/master
# show diffs of changes
git diff master..origin/master
# apply the changes by merge..
git merge origin/master
# .. or just pull the changes
git pull

You want to push your local files to remote files

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
git push -f <remote> <branch>
git push -f <remote> <branch>
git push -f <remote> <branch>
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
git push -f origin master
git push -f origin master
git push -f origin master

Configure Hooks

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
git config --global core.hooksPath .githooks
mkdir .githooks
cp .git/hooks/* .githooks
git config --global core.hooksPath .githooks mkdir .githooks cp .git/hooks/* .githooks
git config --global core.hooksPath .githooks
mkdir .githooks
cp .git/hooks/* .githooks

commit-msg

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
#!/bin/sh
#
NAME=$(git rev-parse --abbrev-ref HEAD)
DESCRIPTION=$(git config branch."$NAME".description)
echo "$NAME"': '$(cat "$1") > "$1"
if [ -n "$DESCRIPTION" ]
then
echo "" >> "$1"
echo $DESCRIPTION >> "$1"
fi
#!/bin/sh # NAME=$(git rev-parse --abbrev-ref HEAD) DESCRIPTION=$(git config branch."$NAME".description) echo "$NAME"': '$(cat "$1") > "$1" if [ -n "$DESCRIPTION" ] then echo "" >> "$1" echo $DESCRIPTION >> "$1" fi
#!/bin/sh
#

NAME=$(git rev-parse --abbrev-ref HEAD) 
DESCRIPTION=$(git config branch."$NAME".description)

echo "$NAME"': '$(cat "$1") > "$1"
if [ -n "$DESCRIPTION" ] 
then
   echo "" >> "$1"
   echo $DESCRIPTION >> "$1"
fi

prepare-commit

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
#!/bin/sh
#
COMMIT_MSG_FILE=$1
COMMIT_SOURCE=$2
SHA1=$3
branchPath=$(git symbolic-ref -q HEAD)
branchName=${branchPath##*/}
if [ -n "$branchName" ]; then
echo "$branchName | $(cat $1)" > $1
fi
#!/bin/sh # COMMIT_MSG_FILE=$1 COMMIT_SOURCE=$2 SHA1=$3 branchPath=$(git symbolic-ref -q HEAD) branchName=${branchPath##*/} if [ -n "$branchName" ]; then echo "$branchName | $(cat $1)" > $1 fi
#!/bin/sh
#

COMMIT_MSG_FILE=$1
COMMIT_SOURCE=$2
SHA1=$3

branchPath=$(git symbolic-ref -q HEAD)
branchName=${branchPath##*/}


if [ -n "$branchName" ]; then
    echo "$branchName | $(cat $1)" > $1
fi
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
file=$(git config hooks.versionfilename)
if [[ -z $file ]]
then
file=".version"
fi
# Version number
echo "$(git rev-parse --abbrev-ref HEAD): $(git describe --tags --long)" >$file
exec git add $file
file=$(git config hooks.versionfilename) if [[ -z $file ]] then file=".version" fi # Version number echo "$(git rev-parse --abbrev-ref HEAD): $(git describe --tags --long)" >$file exec git add $file
file=$(git config hooks.versionfilename)
if [[ -z $file ]]
then
  file=".version"
fi

# Version number
echo "$(git rev-parse --abbrev-ref HEAD): $(git describe --tags --long)" >$file

exec git add $file

pre-commit

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
#!/bin/sh
_BRANCHPATH=$(git symbolic-ref -q HEAD)
_BRANCHNAME=${_BRANCHPATH##*/}
_TIMESTAMP="$(date '+
echo "HOOK : $0"
echo "PARAMETER : '$*''"
echo "BRANCHPATH: $_BRANCHPATH"
echo "BRANCHNAME: $_BRANCHNAME"
LOG() {
[[ "$GIT_COMMIT_DETAILED_LOGGING" == "YES" ]] && echo "LOG: $*"
}
REPLACE()
{
local _TYP; _TYP="$1"; shift
local _TAG; _TAG="$1"; shift
local _WITH; _WITH="$1"; shift
local _FILE; _FILE="$1"; shift
case "$_TYP" in
PYTHON) perl -pi -e 's/(\s*)(__DEPLOY_'${_TAG}'\s*=\s*)(".+")/${1}${2}"'"${_WITH}"'"/' "${_FILE}"
;;
*) LOG "Undefined typ '$TYP' for file $_FILE"
;;
esac
rm -f "${_FILE}.bak"
}
LOG "working on branch $_BRANCH"
for _FILE in $(git diff-index --name-status --cached HEAD | grep -v ^D | cut -c3-)
do
LOG "checking: $_FILE"
# Only examine known text files
if [[ "$_FILE" =~ [.](py)$ ]]; then
LOG "patching: $_FILE"
REPLACE PYTHON TAG "$_BRANCHNAME" "$_FILE"
REPLACE PYTHON TIMESTAMP "$_TIMESTAMP" "$_FILE"
fi
done
#!/bin/sh _BRANCHPATH=$(git symbolic-ref -q HEAD) _BRANCHNAME=${_BRANCHPATH##*/} _TIMESTAMP="$(date '+ echo "HOOK : $0" echo "PARAMETER : '$*''" echo "BRANCHPATH: $_BRANCHPATH" echo "BRANCHNAME: $_BRANCHNAME" LOG() { [[ "$GIT_COMMIT_DETAILED_LOGGING" == "YES" ]] && echo "LOG: $*" } REPLACE() { local _TYP; _TYP="$1"; shift local _TAG; _TAG="$1"; shift local _WITH; _WITH="$1"; shift local _FILE; _FILE="$1"; shift case "$_TYP" in PYTHON) perl -pi -e 's/(\s*)(__DEPLOY_'${_TAG}'\s*=\s*)(".+")/${1}${2}"'"${_WITH}"'"/' "${_FILE}" ;; *) LOG "Undefined typ '$TYP' for file $_FILE" ;; esac rm -f "${_FILE}.bak" } LOG "working on branch $_BRANCH" for _FILE in $(git diff-index --name-status --cached HEAD | grep -v ^D | cut -c3-) do LOG "checking: $_FILE" # Only examine known text files if [[ "$_FILE" =~ [.](py)$ ]]; then LOG "patching: $_FILE" REPLACE PYTHON TAG "$_BRANCHNAME" "$_FILE" REPLACE PYTHON TIMESTAMP "$_TIMESTAMP" "$_FILE" fi done
#!/bin/sh

_BRANCHPATH=$(git symbolic-ref -q HEAD)
_BRANCHNAME=${_BRANCHPATH##*/}

_TIMESTAMP="$(date '+

echo "HOOK      : $0"
echo "PARAMETER : '$*''"
echo "BRANCHPATH: $_BRANCHPATH"
echo "BRANCHNAME: $_BRANCHNAME"

LOG() {
    [[ "$GIT_COMMIT_DETAILED_LOGGING" == "YES" ]] && echo "LOG: $*"
}

REPLACE()
{
   local _TYP;   _TYP="$1"; shift
   local _TAG;   _TAG="$1"; shift
   local _WITH; _WITH="$1"; shift
   local _FILE; _FILE="$1"; shift

   case "$_TYP" in
      PYTHON)   perl -pi -e 's/(\s*)(__DEPLOY_'${_TAG}'\s*=\s*)(".+")/${1}${2}"'"${_WITH}"'"/' "${_FILE}"
                ;;
      *)        LOG "Undefined typ '$TYP' for file $_FILE"
                ;;
   esac

   rm -f "${_FILE}.bak"
}

LOG "working on branch $_BRANCH"

for _FILE in $(git diff-index --name-status --cached HEAD | grep -v ^D | cut -c3-)
do
    LOG "checking: $_FILE"

    # Only examine known text files
    if [[ "$_FILE" =~ [.](py)$ ]]; then
        LOG "patching: $_FILE"

        REPLACE PYTHON TAG       "$_BRANCHNAME" "$_FILE"
        REPLACE PYTHON TIMESTAMP "$_TIMESTAMP"  "$_FILE"
    fi
done

Get Information

git rev-parse –abbrev-ref HEADget branch namefeature/add-new-content
git symbolic-ref -q HEADrefs/heads/feature/add-new-content
git rev-parse –show-toplevelshow current path of git repository

Config

Change Github repository for local clone

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
cd <original repository>
git remote set-url origin https://github.com/<new git user>/<new project name>
git push -u origin master
cd <original repository> git remote set-url origin https://github.com/<new git user>/<new project name> git push -u origin master
cd <original repository>
git remote set-url origin https://github.com/<new git user>/<new project name>
git push -u origin master

CR/LF Mapping

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
git config core.autocrlf true
git config --global core.safecrlf false
git config core.autocrlf true git config --global core.safecrlf false
git config core.autocrlf true
git config --global core.safecrlf false

Create Release

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
#!/bin/bash
if [ $# -ne 1 ]; then
echo "Syntax: release [VERSION]"
exit 1
fi
VERSION=$1
# Create release
git flow release start $VERSION || exit 1
GIT_MERGE_AUTOEDIT=no git flow release finish -m $VERSION $VERSION
# Publish release
git push origin HEAD --tags
# Merge release into develop
git checkout develop
git merge master
#!/bin/bash if [ $# -ne 1 ]; then echo "Syntax: release [VERSION]" exit 1 fi VERSION=$1 # Create release git flow release start $VERSION || exit 1 GIT_MERGE_AUTOEDIT=no git flow release finish -m $VERSION $VERSION # Publish release git push origin HEAD --tags # Merge release into develop git checkout develop git merge master
#!/bin/bash

if [ $# -ne 1 ]; then
  echo "Syntax: release [VERSION]"
  exit 1
fi

VERSION=$1

# Create release
git flow release start $VERSION || exit 1
GIT_MERGE_AUTOEDIT=no git flow release finish -m $VERSION $VERSION

# Publish release
git push origin HEAD --tags

# Merge release into develop
git checkout develop
git merge master