Sign In
Sign In

Git in Visual Studio Code

Git in Visual Studio Code
Hostman Team
Technical writer
Git
12.02.2024
Reading time: 7 min

The Visual Studio Code (VS Code) code editor is one of the most popular platforms for web developers, with wide built-in functionality, including integration with source code management tools. Using Git with Visual Studio Code significantly simplifies the code editing process and increases the efficiency of the development process.

System requirements

All you need for the platform to function is an up-to-date release of Visual Studio Code and the Git package. You can choose a local computer with Linux, macOS, or Windows of any version as a test base. Theoretically, you can also use a VPS/VDS virtual machine with Windows, but working through the Windows Server GUI will be less convenient.

Step 1: First look at the Source Control tab

Before you start working with Git and studying its advantages in source code control, you must initialize your project as a repository. This procedure requires launching the VS Code editor itself beforehand. After that, you need to launch the terminal that's already integrated with it. The key combination <CTRL and +> will help.

In the terminal, we will create a folder for the new task and go to it:

mkdir git_test
cd git_test

Now, initialize the Git repository:

git init

The same Git settings are available in the Visual Studio Code interface. Open the Source Control window on the left side of the panel (the fork icon) and click Open Folder.

Image1

It will open the file manager with the current folder open by default. If you prefer a different folder, you can select it by clicking Open followed by Initialize Repository.

Once initialized, the .git directory will appear in the drive's file system. To view it, enter in the terminal:

ls -la

The result will look like this:

..
.git

The screen's contents indicate that the repository has been initialized, and now you need to add the index.html file. After you create it, you will see a U next to its name in the Source Control panel. It shows the untracked files, which include all newly created or edited files that have not been moved to the repository archive.

To add an object, just click the "plus" icon next to the created index.html.

Image3

The appearance of the letter A tracks the status change: it indicates that Visual Studio and Git have started "working together". All that remains is to click the checkbox at the top of the Source Control panel and make sure there are no unsaved changes.

Image4

To see how the system works, let's edit the index.html file. For example, create a <body> section and a <h1> level header inside it with any content. After saving the file, the letter M will appear next to the file name.

This indicates the difference between the copy stored in Git vs stored locally. If our adjustments are correct, we can send them to the repository using the same checkmark icon.

Image5

We have briefly familiarized ourselves with how to work with Git in the Visual Studio Code. Now, let's look at the options for interpreting Gutter metrics.

Step 2: Interpreting Gutter metrics

Let's begin by defining what the Gutter is. Formally, it is just a certain area located to the right of the line number. It contains the "Collapse" and "Expand" icons necessary to collapse and expand the code when editing. It also has other functionality.

Thus, when making changes, for example, inside the <h1> tag, you can see that the line with new data is marked with a blue vertical line in the Gutter area. This will happen to all previously created lines where you enter a new code.

The program marks the deletion of lines or their parts in a similar way. To check this, let's delete any content of the <body> section, and as a result, we will see a red triangle appearing in the same Gutter area. A group of lines will also be marked with the same sign, for example, if you cut a piece of code consisting of several lines.

When adding a brand new line rather than editing an existing line, the program displays a vertical green bar, and this indicator is again located in the Gutter area. With this approach, the developer sees visually separated parts of the former code where no changes have been made. It is easy to double-check the code adjustments before saving the file to ensure no errors.

Image2

Step 3: Viewing file differences

The VS Code tool helps to quickly compare two versions of a file. Suppose you edit the index.html file and want to see all changes at a glance. Of course, you can use the diff file comparison utility, but working with the VS Code built-in functionality is more convenient.

All you need to do is open the code control panel and double-click on the edited object. The system will automatically open a window for comparison and display the latest version of the code on the left, with the version previously moved to the repository on the right. The differences will be marked green if there is code in the line and gray if there is none.

Step 4: Working with branching

VS Code software supports editing with code branching. The name of the current branch is displayed at the bottom left of the editor window, next to the source code control icon (the fork icon). By default, the program shows the main branch. To make a branch from it, click on its name and select Create new branch in the opened menu. 

For example, let's create a test branch called test. After saving, make any changes to the index.html file. You'll be able to go to the master branch and back to the test branch (on the bottom left of the editing screen). If you go to the master branch, you will see that the edits you made in the branch is not in the code, as it should be. To save the changes, upload the object to the repository and check its current status (the letter A should be displayed).

Step 5: Support for remote repositories

The functionality of the Source Control panel includes support for remote repositories. We will not go into this topic in this article as here we just learn how to apply working with Git for Visual Studio Code, but this feature is definitely worth mentioning. 

Step 6: Installing extension modules

You can expand Virtual Studio Code's built-in functionality further with downloadable extensions. It turns the product into a versatile, flexible tool for creating almost any web solution. Here are examples of several popular modules.

Git Blame

The extension is intended to save and display information about the author of the edits. It is convenient when several people edit one code, for example, at different stages of project development or simply when employees change. In the Git Blame panel, you can see the ID of the "culprit" for each of the selected lines. It also shows the date and time of all corrections made to a particular code section.

Git History

This module supplements the built-in version comparison and branching control functionality by introducing the Git history view right into Visual Code. It shows the list of authors, individual branches, etc. To open the history, right-click on an object and go to the Git: View File History section in the drop-down menu.

Git Lens

The Git Lens extension is designed to visualize the code sections' authorship by annotating them. A developer can view the information attached to files in the Git repository directly in the Visual Studio Code environment. It is very convenient when there's a whole team working on the project, including third-party specialists.

The Git Lens module can easily replace the previous two modules mentioned above. It displays the data about the latest changes and their author to the right of the line being edited. It also indicates whether these adjustments have been saved in the repository. When you hover over it, the system will display a pop-up window with more detailed information.

Conclusions

In this article, we talked about how to use Git in Visual Studio Code to make developing more efficient.

Visual Studio Code Editor is a powerful web tool for developing websites and other online products. Even the built-in functionality is enough to easily create new projects, finalize old ones, and involve additional people in the work. If that is not enough, the system supports downloading extensions that introduce new functions, either replacing standard ones or adding new features to them.

Git
12.02.2024
Reading time: 7 min

Similar

Git

Git Rebase: How It Works and Why You Should Use It

In the Git version control system, there are two ways to combine one branch with another, represented by different commands: git merge. Commits from one branch are transferred into another by creating a merge commit. git rebase. Commits from one branch are transferred into another branch while preserving the original order of changes. Simply put: with git merge, the commits from one branch are “squashed” into one, while with git rebase they remain untouched, yet the branches are combined. Thus, the git rebase command allows you to combine commits from both branches by forming a shared history of changes. This guide will cover the git rebase command, which is responsible for rebasing commits (changes) from one branch to another. All the examples shown used Git version 2.34.1, running on a Hostman server with the Ubuntu 22.04 operating system. You can use these guides to install Git on your machine: Installing Git on Ubuntu Installing Git on Windows Understanding Git Rebase The best way to understand how rebasing works in Git is to look at an abstract repository consisting of several branches. At the same time, the rebasing operation should be considered step by step. Creating Branches Let’s assume we created a repository with a single branch master, containing just one commit. The master branch looks like this: master   commit_1 Then, based on master, we created a new branch hypothesis, where we decided to test some features. In this new branch, we made several commits improving the code. The branch now looks like this: hypothesis   commit_4   commit_3   commit_2   commit_1 Later, we added another commit to the master branch, urgently fixing a vulnerability. The master branch now looks like this: master   commit_5   commit_1 Now our repository has two branches: master   commit_5   commit_1 hypothesis   commit_4   commit_3   commit_2   commit_1 The master branch is the main branch, while hypothesis is secondary (derived). Later commits are listed above earlier ones, similar to the output of the git log command. Merging Branches Let’s say we want to continue working on the feature we had previously moved into the separate hypothesis branch. However, this branch does not contain the critical vulnerability fix we made in master. Therefore, we want to “synchronize” the state of hypothesis with master so that the fix commit also appears in the feature branch. In other words, we want the repository structure to look like this: master   commit_5   commit_1 hypothesis   commit_4   commit_3   commit_2   commit_5   commit_1 As you can see, the hypothesis branch now exactly repeats the history of master, even though it was originally created before commit_5. In other words, hypothesis now contains the history of both branches—its own and master. To achieve this, we need to rebase using the git rebase command. Afterward, the changes made in hypothesis can be merged into master using the classic git merge command, which creates a merge commit. Then the repository structure will look like this: master   commit_merge   commit_5   commit_1 hypothesis   commit_4   commit_3   commit_2   commit_5   commit_1 Moreover, running git merge after git rebase can reduce the likelihood of conflicts. Practice: git rebase Now that we’ve covered the theoretical aspect of the git rebase command, we can move on to testing it in a real repository of an improvised project. The repository structure will repeat the earlier theoretical example. Creating a Repository First, let’s create a separate directory to hold the repository: mkdir rebase Then move into it: cd rebase Now we can initialize the repository: git init In the console, a standard informational message should appear: hint: Using 'master' as the name for the initial branch. This default branch name hint: is subject to change. To configure the initial branch name to use in all hint: of your new repositories, which will suppress this warning, call: ... And in the current directory, a hidden .git folder will appear, which you can view with the following command: ls -a The -a flag means all and allows viewing the file system in extended mode. Its contents will be: .  ..  .git Before making commits, we need to specify some basic user information. First, the name: git config --global user.name "NAME" Then the email: git config --global user.email "NAME@HOST.COM" Populating the master Branch Using simple text files, we will simulate adding different functions to the project. Each new function will be represented as a separate commit. Create a file for the first improvised function: nano function_1 Fill it with the content: Function 1 Now index the changes made in the repository: git add . Just in case, check the indexing status: git status In the console, the following message should appear, showing the indexed changes: On branch master No commits yet Changes to be committed: (use "git rm --cached <file>..." to unstage) new file: function_1 Now we can commit: git commit -m "commit_1" The console should display a message confirming the successful commit into master: [master (root-commit) 4eb7cc3] commit_1  1 file changed, 1 insertion(+)  create mode 100644 function_1 Populating the hypothesis Branch Now let’s create a new branch called hypothesis: git checkout -b hypothesis The -b flag is necessary to switch immediately to the new branch. The console will display a confirmation message: Switched to a new branch 'hypothesis' Next, we need to make three commits in sequence with three files, similar to master: commit_2 with file function_2 and content: Function 2 commit_3 with file function_3 and content: Function 3 commit_4 with file function_4 and content: Function 4 If we then check the commit list: git log --oneline The console will display the following sequence: d3efb82 (HEAD -> hypothesis) commit_4 c9f57b7 commit_3 c977f16 commit_2 4eb7cc3 (master) commit_1 Here, the --oneline flag is used to display commit information in a compressed single-line format. Adding a Commit to the master Branch The last step is to add another commit to the main branch master. Let’s switch to it: git checkout master The console will confirm the switch: Switched to branch 'master' Now create another improvised function file: nano function_5 With the following content: Function 5 Next, index the changes: git add . And make the new commit: git commit -m "commit_5" If we check the current commit list: git log --oneline The master branch will now have two commits: 3df7a00 (HEAD -> master) commit_5 4eb7cc3 commit_1 Merging Branches with git rebase To perform rebasing, first you need to switch to the hypothesis branch: git checkout hypothesis And run the rebase: git rebase master After this, the console will display a message confirming a successful rebase: Successfully rebased and updated refs/heads/hypothesis. Now you can check the commit list: git log --oneline The console will show a list containing the commits of both branches in the original order: 8ecfd58 (HEAD -> hypothesis) commit_4 f715aba commit_3 ee47470 commit_2 3df7a00 (master) commit_5 4eb7cc3 commit_1 Now the hypothesis branch contains the complete history of the entire repository. Resolving Conflicts Just like with git merge, when using the git rebase command, conflicts may occur that require manual resolution. Let’s modify our repository in such a way that we artificially create a rebase conflict. Create another file in the hypothesis branch: nano conflict And write the following text into it: There must be a conflict here! Index the changes: git add . And make another commit: git commit -m "conflict_1" Now switch to the master branch: git checkout master Create a similar file: nano conflict And fill it with the following content: There must NOT be a conflict here! Again, index the changes: git add . And make a commit: git commit -m "conflict_2" Reopen the created file: nano conflict And change its content to: There definitely must NOT be a conflict here! Again, index the changes: git add . And make another commit: git commit -m "conflict_3" Now switch back to the hypothesis branch: git checkout hypothesis And perform another rebase: git rebase master The console will display a conflict message: Auto-merging conflict CONFLICT (add/add): Merge conflict in conflict error: could not apply 6003ed7... conflict_1 hint: Resolve all conflicts manually, mark them as resolved with hint: "git add/rm <conflicted_files>", then run "git rebase --continue". hint: You can instead skip this commit: run "git rebase --skip". hint: To abort and get back to the state before "git rebase", run "git rebase --abort". Could not apply 6003ed7... conflict_1 Git suggests editing the conflict file, indexing the changes with git add, and then continuing the rebase using the --continue flag. That’s exactly what we will do: nano conflict The file will contain two conflicting versions wrapped in special markers: <<<<<<< HEAD There definitely must NOT be a conflict here! ======= There must be a conflict here! >>>>>>> 6003ed7 (conflict_1) Our task is to remove the unnecessary parts and fill the file with a final version of arbitrary text: There must absolutely definitely unanimously NOT be any conflict here! Now index the changes: git add . And continue the rebase: git rebase --continue After this, the console will open a text editor suggesting you modify the original commit message of the commit where the conflict occurred: conflict_1 # Please enter the commit message for your changes. Lines starting # with '#' will be ignored, and an empty message aborts the commit. # # interactive rebase in progress; onto bd7aefc # Last commands done (4 commands done): # pick 8ecfd58 commit_4 # pick 6003ed7 conflict_1 # No commands remaining. # You are currently rebasing branch 'hypothesis' on 'bd7aefc'. # # Changes to be committed: # modified: conflict # The console will then display a message about the successful completion of the rebase process: [detached HEAD 482db49] conflict_1  1 file changed, 1 insertion(+), 1 deletion(-) Successfully rebased and updated refs/heads/hypothesis. Now if you check the commit list in the hypothesis branch: git log --oneline You will see the original sequence of all changes made: 482db49 (HEAD -> hypothesis) conflict_1 bd5d036 commit_4 407e245 commit_3 948b41c commit_2 bd7aefc (master) conflict_3 d98648d conflict_2 3df7a00 commit_5 4eb7cc3 commit_1 Notice that the commits conflict_2 and conflict_3, made in the master branch, appear in the history earlier than the conflict_1 commit. However, this applies to any commits made in the master branch. Rebasing a Remote Repository In addition to working with local branches, rebasing can be done when pulling changes from a remote repository. To do this, you need to add the --rebase flag to the standard pull command: git pull --rebase remote branch Where: remote is the remote repository branch is the remote branch Essentially, this pull configuration is equivalent to git rebase, except that the changes (commits) applied to the current branch are taken from the remote repository. Advantages of git rebase Linearity  The git rebase command makes it possible to form a fairly linear history of the target branch, consisting of sequentially made commits. Such a sequence without branching makes the history easier to perceive and understand. Fewer conflicts  Running git rebase beforehand can significantly reduce the likelihood of conflicts when merging branches with git merge. Conflicts are easier to resolve in sequential commits rather than in commits merged into a single merge commit. This is especially relevant when pushing branches to remote repositories. Disadvantages of git rebase History modification  Unlike merging, rebasing partially rewrites the history of the target branch, removing unnecessary history elements. Risk of errors  The ability to significantly restructure commit history can lead to irreversible errors in the repository. This means that some data may be permanently lost. Conclusion Merging two branches using rebasing, implemented with the git rebase command, is fundamentally different from the classic merge done with the git merge command. git merge turns the commits of one branch into a single commit in another. git rebase moves commits from one branch to the end of another while preserving the original order. A similar rebasing effect can also be achieved when using the git pull command with the additional --rebase flag. On one hand, the git rebase command allows you to achieve a cleaner and more understandable commit history in the main branch, which increases the maintainability of the repository. On the other hand, git rebase reduces the level of detail in changes within the branch, simplifying the history and removing some of its records. For this reason, rebasing is a feature intended for more experienced users who understand how Git works. Most often, the git rebase command is used together with the git merge command, allowing you to achieve the most optimal repository and branch structure.
16 September 2025 · 11 min to read
Microservices

Sending and Applying Git Patches via Email – No GitHub Needed

Git today is the most widespread and popular version control system. Probably 99% of all current projects use Git, from the Linux Kernel to simple JavaScript libraries consisting of just one file and one function. The Linux Kernel is a huge and very complex project. It involves a large number of programmers worldwide. Coordinating changes in this project would be simply impossible without an effective solution that allows this entire community to work independently of one another. Now, this seems like a simple and obvious solution. However, the path to it was long and thorny. A Brief Retrospective 1998 was an important year for Linux. Large vendors took notice of the project, and more and more developers joined. At that time, the project followed a fairly simple model for changes: developers would send their patches to Linus Torvalds, who decided whether to include the code or not. Torvalds liked this model because it gave him control over all changes. The patch mechanism was used back when code trees were small and computers were very large. A patch literally was a set of instructions on punch cards telling what and how to replace in a stack of these media to get a new program version. Punch tapes were literally cut into pieces and glued together in a specific way to introduce changes to the program code of that time.   In general terms, a set of patches is a set of instructions that allow editing (semi- or fully automatically) the source program to get a new version. A patch set is always smaller than the full code version. This turned patches into a convenient interface for transferring changes and collaborative programming. Problems arose when the developer community began to grow. Linus Torvalds became a "bottleneck"; the number of patches grew, and the time to review them increased. Developers began using the CVS version control system to ease collaboration. Of course, this went against Torvalds' original policy on Linux kernel changes. He disliked the existence of parallel project branches with their own workflow. On the other hand, developers felt frustrated sending patches to Torvalds, who physically could not review, accept, request fixes, or reject them in a timely manner. Developers complained they had to send multiple emails to get the "benevolent dictator's" attention. And if you’re looking for a reliable, high-performance, and budget-friendly solution for your workflows, Hostman has you covered with Linux VPS Hosting options, including Debian VPS, Ubuntu VPS, and VPS CentOS. The Emergence of Git The solution was to use a decentralized proprietary version control system called BitKeeper. The project used this software for a long time, but eventually, relations between the company developing BitKeeper and the Linux kernel developers soured. There was an amusing paradox: Linux Kernel is an open and free product licensed under the GNU General Public License (GPL). The main GPL principle is that anyone can freely use, distribute, and modify software released under this license, but all modifications must also be released under GPL. BitKeeper, however, was a fully closed proprietary commercial product owned entirely by its company.   Thus, the open and free project used a closed, non-free technology for coordinating development and versioning. Sooner or later, this fragile balance was going to break—and it did. This made using BitKeeper impossible. Torvalds rejected using Subversion and proposed Monotone instead. However, Monotone was unbearably slow. Eventually, Torvalds began writing his own version control system from scratch in C. Thus, Git was born. The new VCS was far from perfect but was positively received by the developer community and quickly gained the necessary tools. The new version control system rapidly gained popularity, and GitHub turned Git into the dominant solution for source code management in both open and commercial projects. Dominant... Indeed, any project, whether small or large (with thousands of contributors), is likely to be registered and hosted on GitHub. Even projects that don't use Git internally (like FreeBSD or OpenBSD) have read-only copies on GitHub. GitHub or Not GitHub? New developers (and not only them) tend to believe that without GitHub, project development and management are impossible. So, when you join a project as a developer (freelancer or FOSS contributor), you’ll be added to the team on this platform. Even if there are only two, three, or four of you... Even if the project consists of just a few dozen source files. GitHub everywhere. Is this good? It’s hard to answer simply yes or no. Certainly, GitHub has many useful tools; it’s convenient, fast, and reliable. Developers feel comfortable there, like in well-worn jeans. However, one should not forget that it’s a paid service managed by the well-known corporation Microsoft. Like any commercial product, GitHub is primarily focused on profit. If, for some reason, your project starts to interfere with that (damaging the platform’s image, etc.), your access will be instantly cut off. Recall the disputes GitHub had with the YouTube Downloader team, whose repositories were blocked, closed, and deleted simply because the RIAA demanded that GitHub restrict access to allegedly copyright-infringing software. This caused some (not a small number) teams to leave GitHub and switch to alternatives like GitLab or Gitea. In summary, setting aside moral and legal aspects, we see a contradiction: Git was designed as a decentralized version control system (unlike Subversion, for example), yet GitHub, which uses Git, enforces centralized management. Moreover, the developer effectively owns nothing; everything belongs to the "managing company." Is there life outside comfort? Can you use this great VCS without a third-party service? Can you accept patches without GitHub and send them to your team for review? Despite GitHub’s strong influence, Git’s architecture remains almost unchanged—it’s still a decentralized version control system. Git imposes absolutely no requirements on the exchange environment. You can use ordinary files (transfer them any way you want, even by copying to external media), upload patches to an FTP server, use SSH, or even Git’s built-in exchange protocol. This is very convenient. Recall the start of this article: Linus Torvalds accepted patches without GitHub (which didn’t exist then) by email and posted results on FTP servers. Sending Patches by Email Now, let's get to the main topic. Suppose we are a small, brave team that wants to be independent from anyone or anything. We have some money to buy a domain, VPS, and corporate email to exchange information and, of course, send and receive patches by email. Let's list tasks to build the necessary infrastructure for our project: Buy a domain. Buy corporate email and link it to our domain. Create mailboxes. Is it mandatory to buy a domain and corporate email? Not at all! You can use free mailboxes without a domain or purchase a domain later when needed. Everything depends on project requirements. However, from the early stages, the project may need a website, messaging (email), file exchange, and deployment infrastructure. You can buy these separately or combine them under one account for your project.  Suppose we are developing a web app and need infrastructure. After buying a domain and setting up DNS, we register as many mailboxes as needed. After creating mailboxes, we must configure access to them in mail clients and Git. Setting Up Git to Send and Receive Patches via Email It all starts with installing a special Git extension package called git-email. This is done using the package manager of your operating system or its distribution. For example: Fedora: sudo dnf install git-email Ubuntu / Debian: sudo apt-get install git-email On Windows, git-email is included in the standard Git installation package. Next step is configuration. In your OS terminal, run: git config --global --edit This will open your favorite terminal (or other) text editor, where you need to add the following lines to your Git configuration (the example uses test credentials; you should use your own!): [user] name = Maria Ortega email = zerozero@hostman-example.com [sendemail] smtpserver = smtp.hostman.com smtpuser = zerozero@hostman.site smtpencryption = ssl smtpserverport = 465 The parameter smtpencryption can be set to either ssl or tls. The second mode uses STARTTLS to initiate communication over an encrypted channel, while the first mode encrypts the connection immediately after it is established. The choice of mode and port depends on your email provider’s requirements. The [user] section is mandatory. Here, you identify yourself, and this information will appear in all patches and commits made by you. For stricter identification of patches and commits, Git supports signing sent information with GPG keys—but that’s another story. Now that we’ve set up Git to send patches via email let’s try it out. First, we need to clone a copy of the current working repository version. There are various ways to do this, which we’ll discuss at the end of the article. After cloning, make some changes to your project. Create a file named log_stderr.go: package main import ( "fmt" "time" "os" ) func logStderr(message string, args ...interface{}) { x := time.Now() fmt.Fprint(os.Stderr, x.Format(time.RFC822)) fmt.Fprint(os.Stderr, " - ") fmt.Fprintf(os.Stderr, message, args...) } Stage and commit the changes: git add log_stderr.go git commit -m "log into stderr func" Now send your patch to the project lead for review: git send-email --to="project-boss@hostman-example.com" HEAD^ The --to argument can accept multiple addresses separated by commas. This way, you can send your patch to all project members. You can also use --cc (carbon copy) to send the patch to additional email addresses separated by commas. This is useful when you want to send patches for review to the entire team or specific interested parties. To avoid specifying recipients every time on the command line, you can add them to your Git config: git config sendemail.to "project-boss@hostman-example.com" git config sendemail.cc "user1@email.tld","user2@email.tld",…,"userN@email.tld" After that, just run: git send-email HEAD^ …And your patch will be sent to the configured addresses. In this example, we sent the current changes from our working copy (HEAD^). You can send any changes, for example, two commits before the current one, or by commit hash. More details are in the Git documentation. Git will generate the patch and try to send it via the SMTP server specified in the config. If the SMTP server requires authentication, you’ll need to enter your password. If you send many patches, this can be tedious. You can save the password in the config, but note it will be stored unencrypted: git config --global sendemail.smtpPass 'your password' A better option might be to configure Git to cache your password for some time: git config --global credential.helper 'cache --timeout 3600' More advanced solutions can use password managers and the git-credential extension, but we won’t cover that here. Receiving and Integrating Patches Your team members receive your patch as a plain text email message, and they can review it—and, imagine that, reject your changes with requests to “fix” or “rewrite.” This is natural and the core of collaborative software development. The freedom and manual patch management are what attract developers to create their own information exchange solutions. What if You Are Asked to Fix Your Patch? Suppose developers ask to reduce calls to the Fprintf function and add a logging severity level. The updated code will look like this: package main import ( "fmt" "time" "os" ) type LogSeverity string const ( ERR LogSeverity = "ERROR" WARN LogSeverity = "WARN" INFO LogSeverity = "INFO" DEBUG LogSeverity = "DEBUG" ) func LogStderr(message string, severity LogSeverity, args ...interface{}) { x := time.Now() fmt.Fprintf(os.Stderr, "%s - %s - ", x.Format(time.RFC822), severity) fmt.Fprintf(os.Stderr, message, args...) fmt.Fprint(os.Stderr, "\n") } Since we’re fixing our previous patch and haven’t released any newer patches, we can simply amend the current commit: git commit -a --amend Now send the patch again, remembering we already configured the recipients: git send-email --annotate -v2 HEAD^ The -v2 flag means this is the second version of the patch. If you need another fix, use -v3, and so on. The --annotate flag allows you to add comments to your email message. Git will open a text editor showing something like: Subject: [PATCH v2] Logging function to stderr --- Added log level, reduced fmt.Fprintf calls Add your notes, save, and close the editor; the patch will then be sent again to the recipients. Always add annotations to your patches—it makes life easier for both you and your colleagues. Typing --annotate every time can get tedious, so you can automate it: git config --global sendemail.annotate yes How to Receive and Apply Patches? Receiving patches is a bit trickier. Git sends specially formatted patches in plain text email messages. There can be many such patches, and Git does not restrict the transport method (email, FTP, etc.), so it doesn’t handle how to receive patches—that’s up to the developer. Just use your mail client’s capabilities. After receiving approved annotated patches, save one or more email messages containing patches in an mbox file (Unix mailbox format). This format stores one or more email messages in a single file. Then run: git am <path_to_patches.mbox> All patches will be incorporated into your working copy. You can continue working and impressing your team. Email-based Git workflows can be as simple or sophisticated as you want. The main thing is that it suits the team and does not create unnecessary inconvenience. It seems there is nothing simpler, neater, or more elegant than working with Git over email. However, there is one major problem: distributing the working copy to new developers joining the project. If the project is large and has a rich history, the repository size might be many megabytes or even gigabytes. Sending that over email is impossible—it’s simply not designed for that. How to Provide a Newcomer with the Entire Project History? Git has an interesting feature called a bundle. It’s a snapshot of the working copy or the entire repository in a binary format of Git changes. Bundles are much more compact than a set of text patches; history and data inside the bundle are compressed, and the format allows transmitting both text and binary data. Project leads or other responsible persons can upload the current project bundle to a file-sharing service—for example, an FTP server or an S3-compatible object storage. The newcomer downloads the project bundle and clones it: git clone project.bundle <new_place> Now <new_place> contains a new working copy ready to work with email patches. However, to be honest, bundles are somewhat of an alternative to the patch email exchange workflow described above. Collaborative work using bundles is a different story.
07 July 2025 · 12 min to read
Git

Working with Git Tags

Git has been around for almost 20 years, yet it remains the most popular distributed version control system. It is best known for GitHub, the largest remote Git repository where developers store their code, document changes, and save previous versions. To help manage versions efficiently, Git provides special markers called tags. This article will explore what Git tags are and how to use them. What Are Git Tags? To understand Git tags, let's first clarify some related concepts. Commit: A commit is a saved version of a project. Branch: A collection of commits that visually represents the history of changes in a project. Multiple branches can exist simultaneously. Now, let’s define tags. Git tags are markers used to highlight important commits. They help track version history, as responsible developers often tag each new version. Like branches, Git tags point to a specific commit, but unlike branches, they do not have a history of commits. Now, let's see how to work with Git tags—create, view, publish, replace, switch, and delete them. How to Create Git Tags Git has two main types of tags: annotated and lightweight. Each is created differently. Creating Annotated Tags Annotated tags store complete version information, including developer names, emails, and timestamps. They are created using special Git flags, -a and -m, as shown in the example below: git tag -a ver-2.5 -m "beta version 2.5" git tag Output: ver-0.1 ver-1.6 ver-2.5 git tag is the main command for working with tags. -a creates an annotated tag with a specified identifier. -m adds a message. If omitted, a text editor will open for message input. To view details of an annotated tag along with its commit, use: git show ver-2.5 Output: tag ver-2.5 Tagger: Marianne Smith <m.smith@company.com> Date: Fri Mar 28 11:02:35 2025 beta version 2.5 commit bf93b7eaa928fd77a55453118313701b04874051 Author: James Brown <j.brown@company.com> Date: Mon Jan 6 09:41:02 2025 This displays the tagger's information, the commit hash, the author, and the creation date. To verify that the tag was created successfully, use: git tag -n Creating Lightweight Tags Lightweight tags are simple pointers to commits, typically used for temporary markers. They store only the commit’s hash. Here’s how to create one: git tag ver-2.5a git tag Output: ver-0.1 ver-1.6 ver-2.5 ver-2.5a ver-2.6 To view a lightweight tag's commit information: git show ver-2.5a Output: commit bf93b7eaa928fd77a55453118313701b04874051 Author: James Brown <j.brown@company.com> Date: Mon Jan 6 09:41:02 2022 -0300 Unlike annotated tags, lightweight tags do not store additional metadata. Adding and Deleting Git Tags in Remote Repositories To push a tag to a remote repository: git push origin ver-2.5 Here, origin refers to the default remote repository. To push all tags at once: git push origin --tags To delete a tag from a remote repository: git push origin --delete ver-2.5 To delete a tag locally (not on the remote repository): git tag -d ver-2.5 Switching Between Tags To switch to a specific tag: git checkout ver-2.5 However, this detaches the HEAD pointer, meaning any subsequent changes will not be associated with any existing branch. If you make changes, create a new branch to keep them: git checkout -b new-branch Viewing a List of Git Tags To list all available tags: git tag Output: ver-0.1 ver-1.6 ver-2.5 ver-2.5a ver-2.6 To filter tags using a pattern: git tag -l *xyz* If you have tags like ver-1.6xyz, ver-2.5xyz, and ver-2.6xyz, this command will output: ver-1.6xyz ver-2.5xyz ver-2.6xyz Reassigning or Replacing Tags To update an existing tag, use the -f flag for forced replacement: git tag -a -f ver-2.5a bf93b7eaa928fd77a55453118313701b04874051 This reassigns the tag to a specific commit hash. However, this will delete the old tag information, so use it carefully. Summary Git tags make version control more flexible and manageable. The commands covered here are simple yet powerful, making them easy to learn even for beginners. 
03 April 2025 · 4 min to read

Do you have questions,
comments, or concerns?

Our professionals are available to assist you at any moment,
whether you need help or are just unsure of where to start.
Email us
Hostman's Support