mirror of
https://github.com/linkedin/school-of-sre
synced 2026-01-20 07:28:03 +00:00
Deployed 4239ecf with MkDocs version: 1.2.3
This commit is contained in:
@@ -2151,7 +2151,7 @@
|
||||
|
||||
|
||||
<h1 id="working-with-branches">Working With Branches</h1>
|
||||
<p>Coming back to our local repo which has two commits. So far, what we have is a single line of history. Commits are chained in a single line. But sometimes you may have a need to work on two different features in parallel in the same repo. Now one option here could be making a new folder/repo with the same code and use that for another feature development. But there's a better way. Use <em>branches.</em> Since git follows tree like structure for commits, we can use branches to work on different sets of features. From a commit, two or more branches can be created and branches can also be merged.</p>
|
||||
<p>Coming back to our local repo which has two commits. So far, what we have is a single line of history. Commits are chained in a single line. But sometimes you may have a need to work on two different features in parallel in the same repo. Now one option here could be making a new folder/repo with the same code and use that for another feature development. But there's a better way. Use <em>branches</em>. Since git follows tree-like structure for commits, we can use branches to work on different sets of features. From a commit, two or more branches can be created and branches can also be merged.</p>
|
||||
<p>Using branches, there can exist multiple lines of histories and we can checkout to any of them and work on it. Checking out, as we discussed earlier, would simply mean replacing contents of the directory (repo) with the snapshot at the checked out version.</p>
|
||||
<p>Let's create a branch and see how it looks like:</p>
|
||||
<pre><code class="language-bash">$ git branch b1
|
||||
@@ -2159,14 +2159,14 @@ $ git log --oneline --graph
|
||||
* 7f3b00e (HEAD -> master, b1) adding file 2
|
||||
* df2fb7a adding file 1
|
||||
</code></pre>
|
||||
<p>We create a branch called <code>b1</code>. Git log tells us that b1 also points to the last commit (7f3b00e) but the <code>HEAD</code> is still pointing to master. If you remember, HEAD points to the commit/reference wherever you are checkout to. So if we checkout to <code>b1</code>, HEAD should point to that. Let's confirm:</p>
|
||||
<p>We create a branch called <code>b1</code>. Git log tells us that <code>b1</code> also points to the last commit (<code>7f3b00e</code>) but the <code>HEAD</code> is still pointing to <code>master</code>. If you remember, <code>HEAD</code> points to the commit/reference wherever you are checkout to. So if we checkout to <code>b1</code>, <code>HEAD</code> should point to that. Let's confirm:</p>
|
||||
<pre><code class="language-bash">$ git checkout b1
|
||||
Switched to branch 'b1'
|
||||
$ git log --oneline --graph
|
||||
* 7f3b00e (HEAD -> b1, master) adding file 2
|
||||
* df2fb7a adding file 1
|
||||
</code></pre>
|
||||
<p><code>b1</code> still points to the same commit but HEAD now points to <code>b1</code>. Since we create a branch at commit <code>7f3b00e</code>, there will be two lines of histories starting this commit. Depending on which branch you are checked out on, the line of history will progress.</p>
|
||||
<p><code>b1</code> still points to the same commit but <code>HEAD</code> now points to <code>b1</code>. Since we create a branch at commit <code>7f3b00e</code>, there will be two lines of histories starting this commit. Depending on which branch you are checked out on, the line of history will progress.</p>
|
||||
<p>At this moment, we are checked out on branch <code>b1</code>, so making a new commit will advance branch reference <code>b1</code> to that commit and current <code>b1</code> commit will become its parent. Let's do that.</p>
|
||||
<pre><code class="language-bash"># Creating a file and making a commit
|
||||
$ echo "I am a file in b1 branch" > b1.txt
|
||||
@@ -2183,7 +2183,7 @@ $ git log --oneline --graph
|
||||
* df2fb7a adding file 1
|
||||
$
|
||||
</code></pre>
|
||||
<p>Do note that master is still pointing to the old commit it was pointing to. We can now checkout to master branch and make commits there. This will result in another line of history starting from commit 7f3b00e.</p>
|
||||
<p>Do note that master is still pointing to the old commit it was pointing to. We can now checkout to <code>master</code> branch and make commits there. This will result in another line of history starting from commit <code>7f3b00e</code>.</p>
|
||||
<pre><code class="language-bash"># checkout to master branch
|
||||
$ git checkout master
|
||||
Switched to branch 'master'
|
||||
@@ -2202,7 +2202,7 @@ $ git log --oneline --graph
|
||||
* 7f3b00e adding file 2
|
||||
* df2fb7a adding file 1
|
||||
</code></pre>
|
||||
<p>Notice how branch b1 is not visible here since we are on the master. Let's try to visualize both to get the whole picture:</p>
|
||||
<p>Notice how branch <code>b1</code> is not visible here since we are on the <code>master</code>. Let's try to visualize both to get the whole picture:</p>
|
||||
<pre><code class="language-bash">$ git log --oneline --graph --all
|
||||
* 60dc441 (HEAD -> master) adding master.txt file
|
||||
| * 872a38f (b1) adding b1 file
|
||||
@@ -2210,10 +2210,10 @@ $ git log --oneline --graph
|
||||
* 7f3b00e adding file 2
|
||||
* df2fb7a adding file 1
|
||||
</code></pre>
|
||||
<p>Above tree structure should make things clear. Notice a clear branch/fork on commit 7f3b00e. This is how we create branches. Now they both are two separate lines of history on which feature development can be done independently.</p>
|
||||
<p>Above tree structure should make things clear. Notice a clear branch/fork on commit <code>7f3b00e</code>. This is how we create branches. Now they both are two separate lines of history on which feature development can be done independently.</p>
|
||||
<p><strong>To reiterate, internally, git is just a tree of commits. Branch names (human readable) are pointers to those commits in the tree. We use various git commands to work with the tree structure and references. Git accordingly modifies contents of our repo.</strong></p>
|
||||
<h2 id="merges">Merges</h2>
|
||||
<p>Now say the feature you were working on branch <code>b1</code> is complete and you need to merge it on master branch, where all the final version of code goes. So first you will checkout to branch master and then you pull the latest code from upstream (eg: GitHub). Then you need to merge your code from <code>b1</code> into master. There could be two ways this can be done.</p>
|
||||
<p>Now say the feature you were working on branch <code>b1</code> is complete and you need to merge it on <code>master</code> branch, where all the final version of code goes. So first, you will <code>checkout</code> to branch <code>master</code> and then you <code>pull</code> the latest code from <code>upstream</code> (eg: GitHub). Then you need to merge your code from <code>b1</code> into <code>master</code>. There could be two ways this can be done.</p>
|
||||
<p>Here is the current history:</p>
|
||||
<pre><code class="language-bash">$ git log --oneline --graph --all
|
||||
* 60dc441 (HEAD -> master) adding master.txt file
|
||||
@@ -2222,7 +2222,7 @@ $ git log --oneline --graph
|
||||
* 7f3b00e adding file 2
|
||||
* df2fb7a adding file 1
|
||||
</code></pre>
|
||||
<p><strong>Option 1: Directly merge the branch.</strong> Merging the branch b1 into master will result in a new merge commit. This will merge changes from two different lines of history and create a new commit of the result.</p>
|
||||
<p><strong>Option 1: Directly merge the branch.</strong> Merging the branch <code>b1</code> into <code>master</code> will result in a new merge commit. This will merge changes from two different lines of history and create a new commit of the result.</p>
|
||||
<pre><code class="language-bash">$ git merge b1
|
||||
Merge made by the 'recursive' strategy.
|
||||
b1.txt | 1 +
|
||||
@@ -2237,8 +2237,8 @@ $ git log --oneline --graph --all
|
||||
* 7f3b00e adding file 2
|
||||
* df2fb7a adding file 1
|
||||
</code></pre>
|
||||
<p>You can see a new merge commit created (8fc28f9). You will be prompted for the commit message. If there are a lot of branches in the repo, this result will end-up with a lot of merge commits. Which looks ugly compared to a single line of history of development. So let's look at an alternative approach</p>
|
||||
<p>First let's <a href="https://git-scm.com/docs/git-reset">reset</a> our last merge and go to the previous state.</p>
|
||||
<p>You can see a new merge commit created (<code>8fc28f9</code>). You will be prompted for the commit message. If there are a lot of branches in the repo, this result will end-up with a lot of merge commits. Which looks ugly compared to a single line of history of development. So let's look at an alternative approach.</p>
|
||||
<p>First, let's <a href="https://git-scm.com/docs/git-reset">reset</a> our last merge and go to the previous state.</p>
|
||||
<pre><code class="language-bash">$ git reset --hard 60dc441
|
||||
HEAD is now at 60dc441 adding master.txt file
|
||||
$ git log --oneline --graph --all
|
||||
@@ -2248,7 +2248,7 @@ $ git log --oneline --graph --all
|
||||
* 7f3b00e adding file 2
|
||||
* df2fb7a adding file 1
|
||||
</code></pre>
|
||||
<p><strong>Option 2: Rebase.</strong> Now, instead of merging two branches which has a similar base (commit: 7f3b00e), let us rebase branch b1 on to current master. <strong>What this means is take branch <code>b1</code> (from commit 7f3b00e to commit 872a38f) and rebase (put them on top of) master (60dc441).</strong></p>
|
||||
<p><strong>Option 2: Rebase.</strong> Now, instead of merging two branches which has a similar base (commit: <code>7f3b00e</code>), let us rebase branch <code>b1</code> on to current master. <strong>What this means is take branch <code>b1</code> (from commit <code>7f3b00e</code> to commit <code>872a38f</code>) and rebase (put them on top of) master (<code>60dc441</code>).</strong></p>
|
||||
<pre><code class="language-bash"># Switch to b1
|
||||
$ git checkout b1
|
||||
Switched to branch 'b1'
|
||||
|
||||
@@ -2348,7 +2348,7 @@
|
||||
<h2 id="prerequisites">Prerequisites</h2>
|
||||
<ol>
|
||||
<li>Have Git installed <a href="https://git-scm.com/downloads">https://git-scm.com/downloads</a></li>
|
||||
<li>Have taken any git high level tutorial or following LinkedIn learning courses<ul>
|
||||
<li>Have taken any git high-level tutorial or following LinkedIn learning courses<ul>
|
||||
<li><a href="https://www.linkedin.com/learning/git-essential-training-the-basics/">https://www.linkedin.com/learning/git-essential-training-the-basics/</a></li>
|
||||
<li><a href="https://www.linkedin.com/learning/git-branches-merges-and-remotes/">https://www.linkedin.com/learning/git-branches-merges-and-remotes/</a></li>
|
||||
<li><a href="https://git-scm.com/doc">The Official Git Docs</a></li>
|
||||
@@ -2356,7 +2356,7 @@
|
||||
</li>
|
||||
</ol>
|
||||
<h2 id="what-to-expect-from-this-course">What to expect from this course</h2>
|
||||
<p>As an engineer in the field of computer science, having knowledge of version control tools becomes almost a requirement. While there are a lot of version control tools that exist today like SVN, Mercurial, etc, Git perhaps is the most used one and this course we will be working with Git. While this course does not start with Git 101 and expects basic knowledge of git as a prerequisite, it will reintroduce the git concepts known by you with details covering what is happening under the hood as you execute various git commands. So that next time you run a git command, you will be able to press enter more confidently!</p>
|
||||
<p>As an engineer in the field of computer science, having knowledge of version control tools becomes almost a requirement. While there are a lot of version control tools that exist today like SVN, Mercurial, etc, Git perhaps is the most used one and this course we will be working with Git. While this course does not start with Git 101 and expects basic knowledge of git as a prerequisite, it will reintroduce the git concepts known by you with details covering what is happening under the hood as you execute various <code>git</code> commands. So that next time you run a <code>git</code> command, you will be able to press <code>enter</code> more confidently!</p>
|
||||
<h2 id="what-is-not-covered-under-this-course">What is not covered under this course</h2>
|
||||
<p>Advanced usage and specifics of internal implementation details of Git.</p>
|
||||
<h2 id="course-contents">Course Contents</h2>
|
||||
@@ -2383,9 +2383,9 @@ Initialized empty Git repository in /private/tmp/school-of-sre/.git/
|
||||
<pre><code class="language-bash">$ ls .git/
|
||||
HEAD config description hooks info objects refs
|
||||
</code></pre>
|
||||
<p>There are a bunch of folders and files in the <code>.git</code> folder. As I said, all these enables git to do its magic. We will look into some of these folders and files. But for now, what we have is an empty git repository.</p>
|
||||
<p>There are a bunch of folders and files in the <code>.git</code> folder. As I said, all these enable git to do its magic. We will look into some of these folders and files. But for now, what we have is an empty git repository.</p>
|
||||
<h3 id="tracking-a-file">Tracking a File</h3>
|
||||
<p>Now as you might already know, let us create a new file in our repo (we will refer to the folder as <em>repo</em> now.) And see git status</p>
|
||||
<p>Now as you might already know, let us create a new file in our repo (we will refer to the folder as <em>repo</em> now.) And see <code>git status</code>:</p>
|
||||
<pre><code class="language-bash">$ echo "I am file 1" > file1.txt
|
||||
$ git status
|
||||
On branch master
|
||||
@@ -2399,7 +2399,7 @@ Untracked files:
|
||||
|
||||
nothing added to commit but untracked files present (use "git add" to track)
|
||||
</code></pre>
|
||||
<p>The current git status says <code>No commits yet</code> and there is one untracked file. Since we just created the file, git is not tracking that file. We explicitly need to ask git to track files and folders. (also checkout <a href="https://git-scm.com/docs/gitignore">gitignore</a>) And how we do that is via <code>git add</code> command as suggested in the above output. Then we go ahead and create a commit.</p>
|
||||
<p>The current git status says <code>No commits yet</code> and there is one untracked file. Since we just created the file, git is not tracking that file. We explicitly need to ask git to track files and folders. (Also checkout <a href="https://git-scm.com/docs/gitignore">gitignore</a>) And how we do that is via <code>git add</code> command as suggested in the above output. Then, we go ahead and create a commit.</p>
|
||||
<pre><code class="language-bash">$ git add file1.txt
|
||||
$ git status
|
||||
On branch master
|
||||
@@ -2416,7 +2416,7 @@ $ git commit -m "adding file 1"
|
||||
1 file changed, 1 insertion(+)
|
||||
create mode 100644 file1.txt
|
||||
</code></pre>
|
||||
<p>Notice how after adding the file, git status says <code>Changes to be committed:</code>. What it means is whatever is listed there, will be included in the next commit. Then we go ahead and create a commit, with an attached messaged via <code>-m</code>.</p>
|
||||
<p>Notice how after adding the file, <code>git status</code> says <code>Changes to be committed:</code>. What it means is whatever is listed there, will be included in the next commit. Then, we go ahead and create a commit, with an attached message via <code>-m</code>.</p>
|
||||
<h3 id="more-about-a-commit">More About a Commit</h3>
|
||||
<p>Commit is a snapshot of the repo. Whenever a commit is made, a snapshot of the current state of repo (the folder) is taken and saved. Each commit has a unique ID. (<code>df2fb7a</code> for the commit we made in the previous step). As we keep adding/changing more and more contents and keep making commits, all those snapshots are stored by git. Again, all this magic happens inside the <code>.git</code> folder. This is where all this snapshot or versions are stored <em>in an efficient manner.</em></p>
|
||||
<h3 id="adding-more-changes">Adding More Changes</h3>
|
||||
@@ -2437,11 +2437,11 @@ create mode 100644 file2.txt
|
||||
* df2fb7a adding file 1
|
||||
</code></pre>
|
||||
<p><code>git log</code>, as the name suggests, prints the log of all the git commits. Here you see two additional arguments, <code>--oneline</code> prints the shorter version of the log, ie: the commit message only and not the person who made the commit and when. <code>--graph</code> prints it in graph format.</p>
|
||||
<p><strong>Now at this moment the commits might look like just one in each line but all commits are stored as a tree like data structure internally by git. That means there can be two or more children commits of a given commit. And not just a single line of commits. We will look more into this part when we get to the Branches section. For now this is our commit history:</strong></p>
|
||||
<p><strong>Now at this moment, the commits might look like just one in each line but all commits are stored as a tree like data structure internally by git. That means there can be two or more children commits of a given commit. And not just a single line of commits. We will look more into this part when we get to the Branches section. For now, this is our commit history:</strong></p>
|
||||
<pre><code class="language-bash"> df2fb7a ===> 7f3b00e
|
||||
</code></pre>
|
||||
<h3 id="are-commits-really-linked">Are commits really linked?</h3>
|
||||
<p>As I just said, the two commits we just made are linked via tree like data structure and we saw how they are linked. But let's actually verify it. Everything in git is an object. Newly created files are stored as an object. Changes to file are stored as an objects and even commits are objects. To view contents of an object we can use the following command with the object's ID. We will take a look at the contents of the second commit</p>
|
||||
<p>As I just said, the two commits we just made are linked via tree like data structure and we saw how they are linked. But let's actually verify it. Everything in git is an object. Newly created files are stored as an object. Changes to file are stored as an objects and even commits are objects. To view contents of an object, we can use the following command with the object's ID. We will take a look at the contents of the second commit:</p>
|
||||
<pre><code class="language-bash">$ git cat-file -p 7f3b00e
|
||||
tree ebf3af44d253e5328340026e45a9fa9ae3ea1982
|
||||
parent df2fb7a61f5d40c1191e0fdeb0fc5d6e7969685a
|
||||
@@ -2450,13 +2450,13 @@ committer Sanket Patel <spatel1@linkedin.com> 1603273316 -0700
|
||||
|
||||
adding file 2
|
||||
</code></pre>
|
||||
<p>Take a note of <code>parent</code> attribute in the above output. It points to the commit id of the first commit we made. So this proves that they are linked! Additionally you can see the second commit's message in this object. As I said all this magic is enabled by <code>.git</code> folder and the object to which we are looking at also is in that folder.</p>
|
||||
<p>Take a note of <code>parent</code> attribute in the above output. It points to the commit id of the first commit we made. So this proves that they are linked! Additionally, you can see the second commit's message in this object. As I said all this magic is enabled by <code>.git</code> folder and the object to which we are looking at also is in that folder.</p>
|
||||
<pre><code class="language-bash">$ ls .git/objects/7f/3b00eaa957815884198e2fdfec29361108d6a9
|
||||
.git/objects/7f/3b00eaa957815884198e2fdfec29361108d6a9
|
||||
</code></pre>
|
||||
<p>It is stored in <code>.git/objects/</code> folder. All the files and changes to them as well are stored in this folder.</p>
|
||||
<h3 id="the-version-control-part-of-git">The Version Control part of Git</h3>
|
||||
<p>We already can see two commits (versions) in our git log. One thing a version control tool gives you is ability to browse back and forth in history. For example: some of your users are running an old version of code and they are reporting an issue. In order to debug the issue, you need access to the old code. The one in your current repo is the latest code. In this example, you are working on the second commit (7f3b00e) and someone reported an issue with the code snapshot at commit (df2fb7a). This is how you would get access to the code at any older commit</p>
|
||||
<p>We already can see two commits (versions) in our git log. One thing a version control tool gives you is ability to browse back and forth in history. For example: some of your users are running an old version of code and they are reporting an issue. In order to debug the issue, you need access to the old code. The one in your current repo is the latest code. In this example, you are working on the second commit (<code>7f3b00e</code>) and someone reported an issue with the code snapshot at commit (<code>df2fb7a</code>). This is how you would get access to the code at any older commit.</p>
|
||||
<pre><code class="language-bash"># Current contents, two files present
|
||||
$ ls
|
||||
file1.txt file2.txt
|
||||
@@ -2480,10 +2480,10 @@ HEAD is now at df2fb7a adding file 1
|
||||
$ ls
|
||||
file1.txt
|
||||
</code></pre>
|
||||
<p>So this is how we would get access to old versions/snapshots. All we need is a <em>reference</em> to that snapshot. Upon executing <code>git checkout ...</code>, what git does for you is use the <code>.git</code> folder, see what was the state of things (files and folders) at that version/reference and replace the contents of current directory with those contents. The then-existing content will no longer be present in the local dir (repo) but we can and will still get access to them because they are tracked via git commit and <code>.git</code> folder has them stored/tracked.</p>
|
||||
<p>So this is how we would get access to old versions/snapshots. All we need is a <em>reference</em> to that snapshot. Upon executing <code>git checkout ...</code>, what git does for you is use the <code>.git</code> folder, see what was the state of things (files and folders) at that version/reference and replace the contents of current directory with those contents. The then-existing content will no longer be present in the local dir (repo) but we can and will still get access to them because they are tracked via <code>git commit</code> and <code>.git</code> folder has them stored/tracked.</p>
|
||||
<h3 id="reference">Reference</h3>
|
||||
<p>I mention in the previous section that we need a <em>reference</em> to the version. By default, git repo is made of tree of commits. And each commit has a unique IDs. But the unique ID is not the only thing we can reference commits via. There are multiple ways to reference commits. For example: <code>HEAD</code> is a reference to current commit. <em>Whatever commit your repo is checked out at, <code>HEAD</code> will point to that.</em> <code>HEAD~1</code> is reference to previous commit. So while checking out previous version in section above, we could have done <code>git checkout HEAD~1</code>.</p>
|
||||
<p>Similarly, master is also a reference (to a branch). Since git uses tree like structure to store commits, there of course will be branches. And the default branch is called <code>master</code>. Master (or any branch reference) will point to the latest commit in the branch. Even though we have checked out to the previous commit in out repo, <code>master</code> still points to the latest commit. And we can get back to the latest version by checkout at <code>master</code> reference</p>
|
||||
<p>Similarly, <code>master</code> is also a reference (to a branch). Since git uses tree like structure to store commits, there of course will be branches. And the default branch is called <code>master</code>. Master (or any branch reference) will point to the latest commit in the branch. Even though we have checked out to the previous commit in out repo, <code>master</code> still points to the latest commit. And we can get back to the latest version by <code>checkout</code> at <code>master</code> reference</p>
|
||||
<pre><code class="language-bash">$ git checkout master
|
||||
Previous HEAD position was df2fb7a adding file 1
|
||||
Switched to branch 'master'
|
||||
@@ -2503,7 +2503,7 @@ file1.txt file2.txt
|
||||
<pre><code class="language-bash">$ cat .git/refs/heads/master
|
||||
7f3b00eaa957815884198e2fdfec29361108d6a9
|
||||
</code></pre>
|
||||
<p>Viola! Where master is pointing to is stored in a file. <strong>Whenever git needs to know where master reference is pointing to, or if git needs to update where master points, it just needs to update the file above.</strong> So when you create a new commit, a new commit is created on top of the current commit and the master file is updated with the new commit's ID.</p>
|
||||
<p>Viola! Where <code>master</code> is pointing to is stored in a file. <strong>Whenever git needs to know where master reference is pointing to, or if git needs to update where master points, it just needs to update the file above.</strong> So when you create a new commit, a new commit is created on top of the current commit and the master file is updated with the new commit's ID.</p>
|
||||
<p>Similary, for <code>HEAD</code> reference:</p>
|
||||
<pre><code class="language-bash">$ cat .git/HEAD
|
||||
ref: refs/heads/master
|
||||
@@ -2515,7 +2515,7 @@ ref: refs/heads/master
|
||||
* 7f3b00e (HEAD -> master) adding file 2
|
||||
* df2fb7a adding file 1
|
||||
</code></pre>
|
||||
<p>Now let's change master to point to the previous/first commit.</p>
|
||||
<p>Now, let's change <code>master</code> to point to the previous/first commit.</p>
|
||||
<pre><code class="language-bash">$ echo df2fb7a61f5d40c1191e0fdeb0fc5d6e7969685a > .git/refs/heads/master
|
||||
$ git log --oneline --graph
|
||||
* df2fb7a (HEAD -> master) adding file 1
|
||||
|
||||
@@ -2151,13 +2151,13 @@
|
||||
|
||||
|
||||
<h1 id="git-with-github">Git with GitHub</h1>
|
||||
<p>Till now all the operations we did were in our local repo while git also helps us in a collaborative environment. GitHub is one place on the internet where you can centrally host your git repos and collaborate with other developers.</p>
|
||||
<p>Till now all the operations we did were in our local repo while git also helps us in a collaborative environment. GitHub is one place on the Internet where you can centrally host your git repos and collaborate with other developers.</p>
|
||||
<p>Most of the workflow will remain the same as we discussed, with addition of couple of things:</p>
|
||||
<ol>
|
||||
<li>Pull: to pull latest changes from github (the central) repo</li>
|
||||
<li>Push: to push your changes to github repo so that it's available to all people</li>
|
||||
<li>Pull: to pull latest changes from GitHub (the central) repo</li>
|
||||
<li>Push: to push your changes to GitHub repo so that it's available to all people</li>
|
||||
</ol>
|
||||
<p>GitHub has written nice guides and tutorials about this and you can refer them here:</p>
|
||||
<p>GitHub has written nice guides and tutorials about this and you can refer to them here:</p>
|
||||
<ul>
|
||||
<li><a href="https://guides.github.com/activities/hello-world/">GitHub Hello World</a></li>
|
||||
<li><a href="https://guides.github.com/introduction/git-handbook/">Git Handbook</a></li>
|
||||
@@ -2168,7 +2168,7 @@
|
||||
applypatch-msg.sample fsmonitor-watchman.sample pre-applypatch.sample pre-push.sample pre-receive.sample update.sample
|
||||
commit-msg.sample post-update.sample pre-commit.sample pre-rebase.sample prepare-commit-msg.sample
|
||||
</code></pre>
|
||||
<p>Names are self explanatory. These hooks are useful when you want to do certain things when a certain event happens. If you want to run tests before pushing code, you would want to setup <code>pre-push</code> hooks. Let's try to create a pre commit hook.</p>
|
||||
<p>Names are self-explanatory. These hooks are useful when you want to do certain things when a certain event happens. If you want to run tests before pushing code, you would want to setup <code>pre-push</code> hooks. Let's try to create a pre commit hook.</p>
|
||||
<pre><code class="language-bash">$ echo "echo this is from pre commit hook" > .git/hooks/pre-commit
|
||||
$ chmod +x .git/hooks/pre-commit
|
||||
</code></pre>
|
||||
|
||||
Reference in New Issue
Block a user