Git: Difference between revisions

No edit summary
 
(5 intermediate revisions by the same user not shown)
Line 3: Line 3:
The bottom line is this: modern software development may take many "forms", but it usually boils down to [http://nvie.com/posts/a-successful-git-branching-model/ this].  Git enables such a branched workflow. That is why distributed version control in general, and git in particular, is the most widely adopted version control system for software development <ref>https://ianskerrett.wordpress.com/2014/06/23/eclipse-community-survey-2014-results/</ref>
The bottom line is this: modern software development may take many "forms", but it usually boils down to [http://nvie.com/posts/a-successful-git-branching-model/ this].  Git enables such a branched workflow. That is why distributed version control in general, and git in particular, is the most widely adopted version control system for software development <ref>https://ianskerrett.wordpress.com/2014/06/23/eclipse-community-survey-2014-results/</ref>


{{Messagebox |
See [[Git/hacks]] for example commands
|type = normal
 
{{Subpages|}}


|text = See [[Git/hacks]] for example commands
}}
== Intro to Git ==
== Intro to Git ==


Line 27: Line 26:
== Initial Configuration ==
== Initial Configuration ==
In your [https://git-scm.com/book/en/v2/Getting-Started-First-Time-Git-Setup first time setting up Git on a new computer], you want to configure your username and email among other settings.
In your [https://git-scm.com/book/en/v2/Getting-Started-First-Time-Git-Setup first time setting up Git on a new computer], you want to configure your username and email among other settings.
<source lang="bash">
<syntaxhighlight lang="bash">
git config --global user.name "Greg Rundlett"
git config --global user.name "Greg Rundlett"
git config --global user.email greg@freephile.com
git config --global user.email greg@freephile.com
Line 35: Line 34:
# store password in memory for an hour
# store password in memory for an hour
git config --global credential.helper 'cache --timeout=3600'
git config --global credential.helper 'cache --timeout=3600'
 
git config --global push.autoSetupRemote true


# recent packaged versions of git might be 1.8.3.1 (CentOS 7.4) whereas the current available is 2.15.1
# recent packaged versions of git might be 1.8.3.1 (CentOS 7.4) whereas the current available is 2.15.1
Line 42: Line 41:
# and adopt the new behavior now, use:
# and adopt the new behavior now, use:
git config --global push.default simple
git config --global push.default simple
</source>
</syntaxhighlight>
=== Example .gitconfig ===
=== Example .gitconfig ===
<code>git config --global -e</code> and paste in the following:
<code>git config --global -e</code> and paste in the following:
<source lang="ini">
<syntaxhighlight lang="ini">
[user]
[user]
         name = Greg Rundlett
         name = Greg Rundlett
Line 100: Line 99:
#      browser = google-chrome
#      browser = google-chrome
         browser = firefox
         browser = firefox
</source>
</syntaxhighlight>


{{Highlight
{{Highlight
Line 106: Line 105:


== Decentralized Workflow and Branching Model ==
== Decentralized Workflow and Branching Model ==
Here's a good explanation on how most groups use Git in a successful branching model for development, "master", release branches, hotfixes, etc.
Now known as the "'''Git Flow'''" model. When using git for software development where you maintain long-running branches for various supported product versions and also work on the 'next' release in sprints or some development cadence, you need to use this model. '''Git Flow''' is a successful branching model for development, "main", release branches, hotfixes, etc. See https://nvie.com/posts/a-successful-git-branching-model/
http://nvie.com/posts/a-successful-git-branching-model/
 


In contrast, the 'GitHub Flow' model where you really only ever have one product that marches forward, the focus is on a simplified fork (branch) and Pull Request (PR) approach. This simplified model is more appropriate for simple products like documentation or a website.
== Submodules ==
== Submodules ==
Using multiple repositories to compose your project.  See https://git-scm.com/book/en/v2/Git-Tools-Submodules
Using multiple repositories to compose your project.  See https://git-scm.com/book/en/v2/Git-Tools-Submodules


<source lang="bash">
<syntaxhighlight lang="bash">
git init myproject
git init myproject
cd myproject
cd myproject
Line 137: Line 135:
git config alias.spush 'push --recurse-submodules=on-demand'
git config alias.spush 'push --recurse-submodules=on-demand'
git config alias.supdate 'submodule update --remote --merge'
git config alias.supdate 'submodule update --remote --merge'
</source>
</syntaxhighlight>


== Tools ==
== Tools ==
Line 147: Line 145:
== Reporting ==
== Reporting ==
How many lines have I contributed since last year?
How many lines have I contributed since last year?
<source lang="bash">
<syntaxhighlight lang="bash">
git log --stat --author $(git config --get user.email) --since="last year" --until="last month" | awk -F',' '/files? changed/ {
git log --stat --author $(git config --get user.email) --since="last year" --until="last month" | awk -F',' '/files? changed/ {
     files += $1
     files += $1
Line 161: Line 159:


}'
}'
</source>
</syntaxhighlight>


== Visualizing ==
== Visualizing ==
Line 228: Line 226:
Generally following the series of instructions at
Generally following the series of instructions at
http://vafer.org/blog/20080115011413  I installed Git-core, gitweb and gitosis on the  host
http://vafer.org/blog/20080115011413  I installed Git-core, gitweb and gitosis on the  host
<source lang="bash">
<syntaxhighlight lang="bash">
# install git, the git-svn tool and the viewvc equivalent
# install git, the git-svn tool and the viewvc equivalent
apt-get install git-core git-svn gitweb
apt-get install git-core git-svn gitweb
Line 308: Line 306:
# and install it
# and install it
apt-get install gitosis
apt-get install gitosis
</source>
</syntaxhighlight>