Skip to content

Bsouro911/lets-learn-git

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 

Repository files navigation

Git - Github

Git is a version control system that allows developers to track changes to their code over time. Github, on the other hand, is a web-based platform that provides hosting for Git repositories.

Github provides a number of features that make it an attractive option for developers using Git. For example, Github makes it easy to collaborate with other developers by allowing them to fork a repository and make changes in their own copy. Developers can then submit a pull request to the original repository owner, who can evaluate the changes and merge them into the main codebase if they are deemed acceptable.

Github also provides a number of tools for managing issues related to a project. Developers can create issues to keep track of bugs, feature requests, and other tasks related to the project. Issues can be assigned to specific developers, labeled, and tracked in a number of different ways.

Overall, Git and Github are powerful tools that are widely used by developers around the world. Whether you're working on a personal project or collaborating with a team, they can help you manage changes to your codebase and keep track of issues related to your project.

  • A version control system allows us to keep track of when and who did what changes to our files. Those can be code, configuration, images, or whatever else we need to track.

  • The diff tool shows all the differences between any type of file. By highlighting what’s changed, it helps us understand the changes and see how the files have been modified.

  • meld, kdiff3, vimdiff shows difference in two files graphically

  • While diff is the command that generates the difference between two files, patch is the command that applies those differences to the original file.

A version control system allows us to keep track of changes made to our files, including code, configuration, images, and more. This helps us to easily see who made what changes and when, allowing for better collaboration and organization within a project.

  • One of the main benefits of a VCS is that you can see the history of how files changed and understand what changed at each step and what motivated the change.
  • By having each change tracked in the VCS, it's very easy to go back to previous versions when an issue with a change is discovered.

The modified, staged, and commit cycle is a fundamental concept in Git. When working with Git, you typically make changes to your files in your local working directory. These changes are considered "modified." In order to commit these changes to your repository, you first need to stage them using the git add command. This tells Git that you want to include these changes in your next commit.

Once you have staged your changes, you can then commit them to your repository using the git commit command. This creates a new commit in your repository's history that includes the changes you made. It's important to write a descriptive commit message that explains what changes you made and why.

By using this cycle of modifying, staging, and committing, you can keep track of changes to your codebase over time and collaborate effectively with other developers.

Anatomy of a Commit Message

A good commit message is clear and concise, and explains what changes were made and why. It should be written in the present tense and provide a high-level overview of the changes. Here is an example of a good commit message:

Add new feature for user authentication #(approx 50 charecters)

This commit adds a new feature for user authentication that allows users to log in using their email address in addition to their username. This feature improves the user experience and makes the login process more secure. #(approx 72 charecters per line)

The first line of the commit message should be a short summary of the changes, followed by a blank line and a more detailed explanation of the changes. It's also a good practice to reference any related issues or pull requests in the commit message.

By following these guidelines, you can write clear and effective commit messages that help you and your team stay organized and on track.

When you use the git commit command with the -a and -m options, you are telling Git to commit all changes in the working directory and write a commit message at the same time. The -a option stands for "all" and tells Git to stage all modified files before committing. The -m option allows you to write a commit message directly on the command line.

For example, if you wanted to commit all changes in the working directory with the message "Update README.md", you would use the following command:

git commit -a -m "Update README.md"

To view the changes made in a specific commit, you can use the command git show <commit_id>. This will display the details of the commit, including the commit message, author, date, and the actual changes made in the commit.

For example, if you wanted to view the changes made in the commit with the ID abc123, you would use the following command:

git show abc123

This will display the details of the commit and the changes made in that commit.

To view a summary of commit statistics, you can use the command git log --stat. This will display a list of all commits in the repository, along with information on the number of files changed, the number of lines added and removed, and the commit message.

git log --stat

This command will show you a list of all commits in the repository, along with summary statistics for each commit. The statistics will include the number of files changed, the number of lines added and removed, and the commit message.

By using this command, you can quickly get an overview of the changes made to a repository and understand how the codebase has evolved over time.

👉 Note:

The following text is related to the git add -p command.

The git add -p command is a powerful tool that allows you to selectively stage changes to your codebase. When you run this command, Git will prompt you with each change that has been made and ask you whether you want to stage it or not.

This can be useful when you have made a number of changes to a file but only want to commit some of them. By using the git add -p command, you can review each change and decide whether or not to include it in your commit.

To use the git add -p command, simply run the following command within your working directory:

git add -p

Git will then prompt you with each change that has been made and ask you whether you want to stage it or not. You can use the y key to stage the change, the n key to skip the change, and the s key to split the change into smaller pieces.

By using the git add -p command, you can keep your commits focused and organized, and ensure that you only commit changes that are relevant to your project.

When you use the command git diff --staged, Git will display the differences between your staged changes and the previous commit. This can be useful for reviewing the changes you are about to commit and ensuring that you are only committing changes that are relevant to your project.

For example, if you wanted to see the differences between your staged changes and the previous commit, you would use the following command:

git diff --staged

Git will then display the differences between your staged changes and the previous commit, allowing you to review the changes before committing them.

By using this command, you can ensure that you are only committing changes that are relevant to your project and avoid including unnecessary changes in your commits.

The git mv command is used to rename or move a file within a Git repository. To use it, replace <file_name> with the current name of the file you want to rename or move, and <new_file_name> with the new name or new location you want to assign to the file.

git mv <file_name> <new_file_name>

This command will rename the file in your working directory and stage the change for the next commit. To complete the operation and commit the change, you can use the git commit

The git rm command is used to remove files from your Git repository. It not only deletes the file from your working directory but also stages the removal so that you can commit the change.

Here's the basic syntax of the git rm command:

git rm <file_name>
git rm -f <f_n>

The command you've provided, echo .DS_STORE > .gitignore, will create a .gitignore file in your current directory with the content .DS_STORE. However, it's important to note that .DS_STORE is a macOS-specific system file, and you may want to ignore it in your Git repository to prevent it from being tracked.

If you want to create a .gitignore file that ignores .DS_STORE and other common files or directories, you can use the following commands:

echo ".DS_STORE" >> .gitignore  # Appends .DS_STORE to .gitignore if it exists
echo "node_modules/" >> .gitignore  # Ignore the node_modules directory
echo "*.log" >> .gitignore  # Ignore log files, e.g., any file with a .log extension

The >> operator appends the specified content to the .gitignore file

The git checkout <file_name> command is used to discard changes made to a specific file in your Git working directory and replace it with the version of the file from the most recent commit.

Here's the basic syntax:

git checkout <file_name>

The git reset HEAD <file_name> command is used to unstage changes for a specific file in your Git repository. It removes the file from the staging area, effectively "unstaging" it while keeping your local changes intact.

Here's the basic syntax:

git reset HEAD <file_name>

The git commit --amend command is used to make changes to the most recent Git commit. It allows you to modify the commit message or add changes you may have forgotten to include in the last commit.

Here's how you can use git commit --amend:

  1. Change the Commit Message:

    If you want to modify the commit message of the last commit, you can use the following command:

    git commit --amend -m "New commit message"

    Replace "New commit message" with the updated message you want to use. This command will replace the commit message of the last commit.

  2. Add Changes:

    If you've made additional changes to the files in your working directory that you want to include in the last commit, follow these steps:

    a. Make your changes to the files.

    b. Stage those changes using git add.

    c. Use git commit --amend without the -m option:

    git commit --amend

    This will open your default text editor, allowing you to modify the commit message if needed. Save and close the editor to finalize the commit.

Important Note:

Be cautious when using git commit --amend, especially if you've already pushed the original commit to a shared repository. Modifying a commit rewrites its history, which can cause problems for collaborators. It's generally safe to use git commit --amend for commits that haven't been pushed yet, but exercise caution when making changes to shared commits.

  • With git revert, a new commit is created with inverse changes. This cancels previous changes instead of making it as though the original commit never happened.

The git revert command is used to create a new commit that undoes the changes made in a previous commit. It's a safe way to reverse the effects of a commit without rewriting Git history. When you run git revert, Git will create a new commit with the opposite changes, effectively "reverting" the commit you specify.

Here's the basic syntax of git revert:

git revert <commit_sha>
  • <commit_sha> is the SHA-1 hash of the commit you want to revert. You can find the commit SHA by using git log.

For example, if you want to revert the changes made in the commit with a specific SHA-1 hash (e.g., abcdef123456), you would run:

git revert abcdef123456

After running this command, Git will create a new commit that undoes the changes introduced by the specified commit. This new commit will have a commit message indicating that it's a "revert" of the original commit.

It's important to note that git revert does not remove or delete the original commit. Instead, it adds a new commit that negates the changes from the original commit.

If you want to revert multiple commits, you can specify a range of commits using a commit range, like this:

git revert <start_commit>^..<end_commit>
  • <start_commit> is the commit at the start of the range (inclusive).
  • <end_commit> is the commit at the end of the range (exclusive).

For example:

git revert abcdef123456^..fedcba987654

This will revert all the commits in the range from abcdef123456 (inclusive) to fedcba987654 (exclusive).

In Git, each branch is essentially a pointer to a specific commit within a series of snapshots. This concept is fundamental to understanding how Git manages version control.

Here's a breakdown of the key points:

  1. Commits: Commits are the core building blocks of Git. Each commit represents a specific state of your project at a particular point in time. A commit contains a snapshot of the entire project's files and directories.
  2. Branches: Branches in Git are lightweight pointers or references that point to a specific commit. They make it easy to work on different lines of development simultaneously. When you create a new branch, it essentially creates a new pointer to a specific commit.
  3. HEAD: The term "HEAD" is used in Git to refer to the currently checked-out branch or commit. It's essentially a special pointer that points to the tip of the currently checked-out branch.
  4. Branching and Merging: You can create branches to work on new features, bug fixes, or experiments independently. When you make new commits on a branch, the branch pointer moves forward to the latest commit. When you merge one branch into another, Git essentially combines the changes from both branches and updates the branch pointer to the new merge commit.
  5. Branching Workflow: Git's branching model allows you to easily switch between different snapshots of your project, collaborate with others, and maintain a clear history of changes.
  • git checkout switch branches by: The HEAD is moved to the relevant commit on the specified branch.

  • If there are changes in the branch we want to delete that haven't been merged back into the master branch, git will let us know with an error.

  • Merging combines branched data and history together.

Git Branching and Merging

This guide explains the concepts of branching and merging in Git, along with the commands you need to work with branches effectively.

What is a Branch?

A branch in Git is a lightweight, movable pointer to a specific commit. Branches allow you to work on different features or bug fixes independently without affecting the main codebase.

Creating a New Branch

To create a new branch, use the following commands:

# List all existing branches
git branch

# Create a new branch with the given name
git branch <name>

# Create and switch to a new branch in one step
git checkout -b <branch>

Working with Branches

# Switch to an existing branch
git checkout <branch>

# Delete a branch (use -d for safe deletion)
git branch -d <name>

# Force delete a branch (use with caution)
git branch -D <name>

Merging

Merging combines changes from one branch into another. Use the following command:

# Merge changes from the specified branch into the current branch
git merge <branch>

Merge Conflicts

Sometimes, conflicts arise when Git can't automatically merge changes. To resolve conflicts:

# Manually edit the conflicted files
# Use git add <file> to stage the resolved files
# Commit the changes with git commit

Additional Commands

# Abort a merge in progress
git merge --abort

# View a simplified graph of commit history
git log --graph --oneline

Basic Interaction with GitHub

There are various remote repository hosting sites:

Follow the workflow at https://github.com/join to set up a free account, username, and password. After that, these steps will help you create a brand new repository on GitHub.

Some useful commands for getting started:

Command Explanation & Link
git clone URL Git clone is used to clone a remote repository into a local workspace
git push Git push is used to push commits from your local repo to a remote repo
git pull Git pull is used to fetch the newest updates from a remote repository. This can be useful for keeping your local workspace up to date.

Additional helpful links:

Working with Git Remotes

What is Remote

In Git, a remote is like a connection to another copy of a repository, typically located on a server or another user's computer. Think of it as a way to share and collaborate on code with others. Remote repositories help you work together on the same project without being in the same place.

Working with Remote

git remote

When you run git remote, Git tells you the names of all the connections (remotes) you have to other repositories. Imagine it as a list of your project's friends – these are the remotes you can interact with.

git remote -v

Adding -v to the command shows not only the names of your remotes but also the web addresses (URLs) where they live. It's like getting the phone numbers of your project's friends so you can call them when needed.

git remote show <name>

This command is like asking for more details about one of your project's friends. It tells you information about a specific remote, such as what branches it knows about and where it lives on the internet.

Fetching New Changes

git remote update

When you tell Git to update, it's like asking your project's friends if they have any news or updates for you. This command fetches the latest information from the remote repositories, making sure your project stays informed.

git fetch

Fetching is like getting a newspaper delivered to your door without actually reading it. Git fetches changes from remote but doesn't automatically apply them to your project. It's a way to see what's new without making changes to your project.

Updating the Local Repository

git branch -r

Running this command is like looking at a list of your project's friends and seeing what they are up to. It shows you a list of remote branches, which are like versions of the project that live in other places. This way, you can stay aware of the different branches in your project's network.

Solving Conflicts in Git

Pull-Merge-Push Workflow

In this workflow, you pull the latest changes from a remote branch, merge them into your local branch, resolve any conflicts, and then push the merged changes back to the remote repository.

Example:

# Start in your local branch
git checkout your-branch

# Pull the latest changes from the remote branch
git pull origin remote-branch

# Resolve any conflicts in your text editor

# Add the resolved files
git add .

# Commit the merge
git commit -m "Merge changes from remote-branch"

# Push the merged changes back to the remote repository
git push origin your-branch

Pushing Remote Branches

You can push your local branch to the remote repository to create a new branch. This is useful when you need to share your work or collaborate on a feature.

Example:

# Create a new branch locally and switch to it
git checkout -b new-feature

# Make changes, commit them

# Push the new branch to the remote repository
git push origin new-feature

Rebasing Your Changes

Rebasing allows you to move your changes to the tip of the branch you're rebasing onto. It can be used to integrate changes from a remote branch into your local branch, making the history cleaner.

Example:

# Start in your local branch
git checkout your-branch

# Fetch the latest changes from the remote branch
git fetch origin remote-branch

# Rebase your changes on top of the latest remote changes
git rebase origin/remote-branch

👉 Note :

In interactive rebase, the default option for taking commits and rebasing them against the branch you selected is pick. The pick option is used to indicate that you want to keep the selected commit as-is during the rebase.

Here's what each of the options does in an interactive rebase:

  • pick: This option keeps the commit unchanged and includes it in the rebase.

  • squash: This option allows you to combine the selected commit with the previous commit, effectively merging them into a single commit.

  • edit: This option allows you to pause the rebase process after the selected commit so that you can make changes to that specific commit (e.g., amending the commit message or modifying the commit content).

  • reword: This option allows you to edit the commit message of the selected commit.

By default, when you start an interactive rebase, all the commits are listed with the pick option, indicating that they will be rebased as-is. You can then interactively choose to modify the behavior of each commit by changing its action in the rebase script.

Fetch-Rebase-Push Workflow

This workflow combines fetching, rebasing, and pushing to keep your local branch up-to-date with a remote branch.

Example:

# Start in your local branch
git checkout your-branch

# Fetch the latest changes from the remote branch
git fetch origin remote-branch

# Rebase your changes on top of the latest remote changes
git rebase origin/remote-branch

# Push the rebased changes back to the remote repository
git push origin your-branch

Collaboration and Pull Requests in Git

Collaboration is a key aspect of successful project management, and Git provides powerful tools for working together on code. In this document, we'll explore how to use Git for collaboration, especially when it comes to creating and managing pull requests.

Introduction

Collaboration in Git involves sharing code changes both locally and remotely. Git offers a range of features to streamline the process, including handling conflicts, tracking work, and contributing to projects hosted on platforms like GitHub.

Collaborative Development Platforms

GitHub, among other platforms, has gained immense popularity for fostering collaboration across various projects. It allows anyone to learn, contribute, and collaborate on code. Let's dive into some essential concepts and workflows for effective collaboration.

A Simple Pull Request on GitHub

A pull request (PR) is a fundamental mechanism for suggesting changes to a project on GitHub. It allows you to propose code modifications, enhancements, or bug fixes to a repository you don't have direct access to. Here's how to create a simple pull request on GitHub.

Forking a Repository

  1. Start by navigating to the repository you want to contribute to.
  2. Click the "Fork" button to create a personal copy of the repository under your GitHub account.
  3. Now, you have your own forked repository where you can make changes.

Editing Files and Committing Changes

  1. Locate the file you want to modify and click the pencil icon to edit it directly on the web interface.
  2. GitHub will automatically create a forked copy, a new branch, and allow you to make changes.
  3. Edit the file, fix the issue, or make improvements.
  4. Provide a clear commit message explaining your changes.
  5. Commit your changes to your forked repository.

Creating a Pull Request

  1. After committing, GitHub will prompt you to create a pull request.
  2. Review your changes and provide additional context in the description box.
  3. Click "Create pull request" to submit your changes for review by the repository owner.
  4. Your pull request is now available for review. The repository maintainers will assess your changes and decide whether to merge them.

The Typical Pull Request Workflow on GitHub

While the previous section covered creating pull requests directly through the GitHub interface, for more complex changes, it's advisable to work with a local copy of the repository. This allows you to preview and test changes before submitting a pull request.

Creating a Local Fork

  1. Go to the repository you want to contribute to.
  2. Click the "Fork" button to create a fork under your GitHub account.
  3. Clone the forked repository to your local machine using git clone.
  4. You now have a local copy of the repository to work on.

Making and Pushing Changes

  1. Create a new branch for your changes using git checkout -b branch-name.
  2. Make your desired code changes, create new files, or add documentation.
  3. Commit your changes with clear messages.
  4. Push your branch to your forked repository using git push origin branch-name.
  5. Your changes are now in your forked repository on GitHub, ready for a pull request.

Creating a Pull Request

  1. Visit your forked repository on GitHub.
  2. Click "Compare & pull request" to create a new pull request.
  3. Review the changes and provide context in the comment box.
  4. Click "Create pull request" to submit your request.
  5. Your pull request is created and can be reviewed by the repository maintainers.

Updating an Existing Pull Request

  • It's common to receive feedback on your pull request, prompting you to make further improvements. Here's how to update an existing pull request.

Addressing Feedback

  1. Review comments and feedback provided by project maintainers.
  2. Make necessary changes in your local repository.
  3. Commit these changes with clear messages.
  4. Push the changes to your existing branch in your forked repository.
  5. Your pull request will automatically update with the new commits.

Squashing Changes

  • Sometimes, project maintainers may ask you to squash your commits into a single commit before merging. This can be done using an interactive rebase.

Squashing Commits

  1. Run git rebase -i master, specifying the base branch.
  2. A text editor will open, showing a list of commits.
  3. Change "pick" to "squash" for the commits you want to squash.
  4. Save and close the editor.
  5. Another editor will open to allow you to modify the combined commit message.
  6. Save and close the editor.
  7. Your commits are now squashed into a single commit with an updated message.

Forking, Cloning, and Pull Requests in Git

This guide explains essential Git operations for collaborating on projects, including forking a repository, cloning it to your local machine, creating branches, making and committing changes, and creating and updating pull requests.

Forking a Repository

To fork a repository on GitHub using the web interface:

  1. Visit the repository you want to fork on GitHub.
  2. Click the "Fork" button, and GitHub will create a fork under your account.

Cloning a Repository to Your Local Machine

To clone your forked repository to your local machine:

# Replace 'your-username' with your GitHub username and 'repo-name' with the repository name.
git clone https://github.com/your-username/repo-name.git
cd repo-name

Creating a New Branch for Your Changes

Create a new branch in your local repository to work on your changes:

# Replace 'branch-name' with your desired branch name.
git checkout -b branch-name
  • Make changes to your code.
# Stage your changes for commit.
git add .

Commit your changes with a clear message.

git commit -m "Fix the typo in numbers.py"

Pushing Your Changes to Your Forked Repository

Push your changes to your forked repository on GitHub:

Replace 'branch-name' with the name of the branch you created.

git push origin branch-name

Creating a Pull Request

After pushing your changes, create a pull request from your GitHub account:

  • Visit your forked repository on GitHub.
  • Click "New Pull Request" to start the pull request process.
  • Review your changes and provide a description.
  • Click "Create Pull Request" to submit your pull request.

Updating an Existing Pull Request

If you receive feedback on your pull request and need to make updates:

# Make changes in your local branch based on the feedback.
# Stage and commit your changes.
git add .
git commit -m "Address feedback from code review"

# Push the changes to your branch in your forked repository.
git push origin branch-name

Squashing Commits

To squash multiple commits into a single commit interactively:

# Start an interactive rebase against the base branch (e.g., master).
git rebase -i master

# In the text editor that opens, change "pick" to "squash" (or "s") for the commits you want to squash.
# Save and close the text editor.

# Another text editor will open for the combined commit message. Modify it as needed.
# Save and close the text editor.

# Force push the changes to your forked repository.
git push -f origin branch-name

Understanding the Code Review Workflow

Requesting a Code Review

  • After completing a set of code changes, developers typically ask a reviewer to evaluate their work.

Reviewer's Feedback

  • Reviewers examine the code and provide feedback.
    • This feedback can include suggestions for improvement and identifying issues.

Addressing Review Comments

  • Developers address review comments, making necessary changes.
    • This may involve fixing typos, adding missing tests, or implementing suggested improvements.

Marking Comments as Resolved

  • After addressing a comment, it can be marked as resolved to indicate that it has been addressed.

Seeking Clarification

  • Developers can seek clarification from reviewers by replying to comments if they are unsure about a particular issue or suggestion.
    • Comments that need further discussion are not marked as resolved.

Approval and Merging

  • Once all comments have been resolved, and the reviewer is satisfied, they approve the changes.
  • The approved changes can then be merged into the codebase.

Understanding Review Comments

Types of Comments

  • Reviewers may provide a range of comments, including:
    • Critical issues that require significant fixes.
    • Minor suggestions for code improvement, often labeled as "Nits."

Improving Code Clarity

  • It's essential to use feedback as an opportunity to enhance code clarity.
    • This can involve improving variable names or breaking down complex code into smaller functions.
    • Adding comments and documentation to explain the "how" and "why" of code.

Style Guide Adherence

  • Code reviews often include comments about coding style.
  • Referring to a project-specific style guide, such as PEP8 for Python, can help streamline discussions about code style.

Code Review Tools

Approval Workflow

  • Different code review tools may have varying approval workflows.
    • Some require approval from project maintainers, while others need a few "+1s" from contributors.

Ensuring Quality

  • The goal is to ensure that code changes have been reviewed by individuals familiar with the project, ensuring its readiness for submission.

The Value of Code Reviews

Benefits

  • Code reviews benefit projects of all sizes and complexities.
    • They facilitate team agreement on coding standards and approaches.
    • They provide a second set of eyes to identify issues and improvements.

Tracking Issues in Project Management

Collaboration and project management are crucial when working with others on a project. Without proper coordination, there's a risk of overlapping efforts and missing critical tasks. Imagine a scenario where you and your colleagues are working on building automation software for your network, but there's no clear plan. This could lead to chaos, incompatible software, and unaddressed gaps in the project.

The Challenge of Collaboration

In small teams, discussing responsibilities is manageable in person. However, as the group grows, managing responsibilities becomes more challenging. This is where issue trackers and bug trackers come to the rescue.

What Is an Issue Tracker?

An issue tracker is a tool that helps coordinate work within a team. It keeps track of tasks, their status, and who is responsible for them. Additionally, users can add comments to issues, which can provide essential details about the problem, suggest solutions, or describe testing procedures.

Issue trackers aren't just for project team members. They also allow users to report bugs and issues they encounter, even if they don't know how to fix them. This helps improve projects by identifying unforeseen problems and inconsistencies. Moreover, issue trackers are valuable for volunteers interested in contributing to a project, as they provide a clear list of pending tasks.

Types of Issue Trackers

Various solutions are available for tracking bugs and issues. Two popular options include:

1. Bugzilla

Bugzilla is a widely-used bug tracker, especially in the open-source community. Many projects rely on it to manage their issues and tasks.

2. GitHub Issue Tracker

GitHub, a popular platform for hosting projects, comes with an integrated issue tracker. This built-in tool simplifies issue management, making it convenient for projects hosted on GitHub.

Using an Issue Tracker in Practice

Let's explore how to use an issue tracker, focusing on GitHub's issue tracker.

Creating a New Issue

  1. Go to the project's issue section.
  2. Click the "New issue" button.
  3. Provide a title for the issue, e.g., "Check for Critical Errors in System Logs."
  4. In the issue description, specify the details of the task, such as checking var/log/currentlog and var/log/syslog for critical errors.

Managing Issues

Issues in the tracker are uniquely identified by numbers. GitHub automatically references issues and pull requests when you mention them using the hashtag format (e.g., #2). This simplifies cross-referencing and tracking.

Assigning Issues

Assigning issues to collaborators helps track who is working on what. By assigning a bug to yourself, you signal to others that you are taking responsibility for it.

Closing Issues

When resolving an issue through a pull request, you can automatically close the issue upon merging. Include a string like "closes:#4" in your commit message or pull request description. GitHub will then close the issue and link it to the new commit.

Real-World Example

Consider a scenario where we need to update documentation for a project called "health-checks." There is an issue requesting this update.

Updating Documentation

  1. Assign the issue to yourself.
  2. Make the necessary updates to the documentation.
  3. Commit the changes with a message like "Updated README for new script name."
  4. Include "closes #1" to automatically close the associated issue when the commit is merged.
  5. Push the commit to the repository.

Closing the Issue

GitHub automatically closes the issue when the commit is pushed. You can click on the commit ID to see the associated change and reference to the issue.

This guide provides a basic understanding of tracking issues in project management. There are more advanced techniques and features to explore, but this should give you a solid foundation for efficient collaboration and issue tracking.

Automated Testing, Continuous Integration, and Continuous Deployment (CI/CD)

Throughout this course, we've been making changes to our files, sometimes we ran them manually to test if they still worked after the change, sometimes we just forgot to do that. This is common for any software project no matter how big or small. As humans, we're not great at remembering to do lots of stuff so we can't rely on people remembering to test their code, not even ourselves. Luckily, we don't need to. We can write automated tests to test the code for us and then use a continuous integration or CI system to run those tests automatically.

Continuous Integration (CI)

A continuous integration system will build and test our code every time there's a change. This means that it will run whenever there's a new commit in the main branch of our code. It will also run for any changes that come in through a pull request. In other words, if we have continuous integration configured for our project, we can automatically run our tests using the code in a pull request. This way, we can verify that the test will pass after the new changes get merged back into the tree and that means instead of hoping our collaborators will remember to properly test their code, we can rely on our automated testing system to do it for us.

Continuous Deployment (CD)

Once we have our code automatically built and tested, the next automation step is continuous deployment which is sometimes called continuous delivery or CD. Continuous deployment means the new code is deployed often. The goal is to avoid rollouts with a lot of changes between two versions of a project and instead do incremental updates with only a few changes at a time. This allows errors to be caught and fixed early. Typical configurations include deploying a new version whenever a commit is merged into the main tree or whenever a branch is tagged for release.

Tools for CI/CD

There's a large world of tools and platforms related to CI/CD which is what the whole system is usually called. One popular option is Jenkins which can be used to automate lots of different types of projects. Some repository hosting services like GitLab provide their own infrastructure for doing continuous integration. GitHub doesn't offer an integrated solution. Instead, the popular alternative is to use Travis which communicates with GitHub and can access the information from GitHub projects to know which integrations to run. No matter which tool you use, there are a bunch of concepts that you'll need to deal with when creating your own CI/CD.

CI/CD Concepts

The first one is the concept of Pipelines.

A pipeline in CI/CD is a series of automated steps or stages that code changes go through from development to deployment. Pipelines are crucial for ensuring that code is thoroughly tested, built, and deployed in a controlled and consistent manner. Here's a breakdown of what pipelines typically include:

  • Build: The first stage of a pipeline involves compiling or building the code. This may involve transforming source code into executable binaries or preparing files for deployment.

  • Test: After the build stage, automated tests are executed. Testing can include unit tests to check individual code components, integration tests to ensure different parts work together, and end-to-end tests to simulate user interactions.

  • Quality Checks: In this stage, code quality checks may be performed. This can involve running static analysis tools to identify coding standard violations, security vulnerabilities, or other issues.

  • Deployment: If all previous stages pass successfully, the code is deployed to a test environment. This environment mimics the production environment but is isolated for testing purposes.

  • Review and Approval: Some pipelines include a manual review and approval step, where designated team members or stakeholders review the changes and approve them for further deployment.

  • Production Deployment: Once approved, the code can be deployed to the production environment. This is often a controlled process with rollback mechanisms in case of issues.

  • Monitoring and Feedback: After deployment, the application is monitored for performance, errors, and other issues. Any problems detected are addressed promptly.

Another concept that turns up when doing CI/CD is Artifacts.

Artifacts refer to the output files or packages generated during the CI/CD pipeline. These files are the result of various stages of the pipeline and are often used for deployment or distribution. Here are some common examples of artifacts:

  • Compiled Binaries: In programming languages like Java, C++, or Go, the artifact might be the compiled binary files that are ready to run.

  • Docker Images: In containerized applications, the artifact can be Docker images that contain the application and its dependencies. These images can be deployed to container orchestration platforms like Kubernetes.

  • Deployment Packages: For web applications or services, artifacts may include deployment packages like WAR files for Java applications, ZIP files, or tarballs containing the application code.

  • Documentation: Sometimes, artifacts include documentation files, such as user manuals, API documentation, or release notes, generated as part of the build process.

  • Installer Packages: In desktop or mobile application development, artifacts can be installer packages for different platforms (e.g., Windows Installer, Debian packages, macOS DMG files).

  • Reports: In cases where the pipeline generates reports (e.g., test reports, code analysis reports), these reports are also considered artifacts and can be valuable for post-deployment analysis.

  • Artifacts are typically stored in a repository or artifact storage system, making them easily accessible for deployment to various environments, sharing with team members, or archiving for future reference.

When setting up CI/CD, we have to be careful about how we manage secrets. If our pipeline includes deploying a new version of the software to a test server, we need to somehow give the software that's running the pipeline access to our test server. There are a bunch of different strategies to do this, like exchanging SSH keys or using application-specific API tokens. For some pipelines, it might be unavoidable to use one of these methods, but be aware that you're giving access to your test servers to the owner of the service that's running the pipeline for you. It's a bit like giving your house keys to the person checking your heating once a year.

Security Considerations

So two things to remember, first, make sure the authorized entities for the test servers are not the same entities authorized to deploy on the production servers. That way, if there's any kind of compromise in the pipeline, your production server is not affected. Second, always have a plan to recover your access in case your pipeline gets compromised.

Getting Started with Travis CI (for GitHub Projects)[optional]

If you want to set up Travis for your GitHub project, you can do that by logging into the Travis website at www.travis-ci.com using your GitHub account, then enable the projects that you want to continuously integrate. After that, you'll need to add a configuration file to your project written in YAML format that states the language your project is in and which steps to take for the pipeline. This file can be very simple if your project files are typical configuration for the language you're using but can also become very complex if you want to run a complicated pipeline with lots of stages and steps outside the defaults. We won't go into a ton of detail here but there's more info in the next reading coming up. Feel free to read up on it and investigate on your own if you want to continuously integrate and deliver your project.

License

Bsouro911 - Sourojyoti Biswas

About

Learn Git-GitHub fundamentals from this repo

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published