Common Git Workflows

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to Lesson

Podcast

Play an AI-generated podcast conversation about this lesson
Download our mobile app to listen on the go
Get App

Questions and Answers

In the centralized workflow, how do developers typically integrate their changes into the main codebase?

  • By creating a pull request for review before merging.
  • By merging their feature branch into the develop branch first.
  • By directly pushing to the central repository, often without extensive branching. (correct)
  • By forking the repository and submitting changes via a pull request.

Which of the following branches in the Gitflow workflow is specifically designated for urgent patches to production releases?

  • hotfix (correct)
  • develop
  • release
  • feature

What is the primary purpose of feature branches in the Feature Branching workflow?

  • To store the currently released version of the code.
  • To provide isolated environments for developing new features or tasks. (correct)
  • To merge all the code from the develop branch.
  • To manage hotfixes for production releases.

A team is using Gitflow. They need to start working on a new feature. From which branch should they create their new feature branch?

<p>develop (A)</p> Signup and view all the answers

In the Forking Workflow, how do contributors typically propose changes to the original repository in open-source projects?

<p>By submitting pull requests from their forked repository. (B)</p> Signup and view all the answers

Which branch should mirror the code currently running in the production environment?

<p>main (A)</p> Signup and view all the answers

A developer identifies a critical bug in the production code. Using Gitflow, from which branch should they create a branch to fix this issue?

<p>main (C)</p> Signup and view all the answers

Which workflow is most similar to version control systems like SVN?

<p>Centralized workflow (C)</p> Signup and view all the answers

A development team is using Git for version control. Which of the following steps should be performed by the team member responsible for GitHub at the beginning of a new project?

<p>Create a repository on GitHub, invite team members, and protect the main branch. (D)</p> Signup and view all the answers

Your team has established a workflow where all changes to the main branch must be submitted via pull requests. What is the primary reason for enforcing this rule?

<p>To ensure code review and approval by a specified number of team members before merging. (A)</p> Signup and view all the answers

A developer has completed a feature in their branch and is ready to submit a pull request. Before creating the pull request, what step should the developer take to ensure a smooth integration?

<p>Merge the main branch into their feature branch to update it with the latest changes. (B)</p> Signup and view all the answers

During a team project, two developers have modified the same file, leading to merge conflicts when one developer tries to merge their branch. What is the recommended approach to resolve these conflicts?

<p>Manually edit the file to integrate both sets of changes, then commit the resolution. (B)</p> Signup and view all the answers

What is the key difference between using merge and rebase when integrating changes from the main branch into a feature branch?

<p>Both B and C (B)</p> Signup and view all the answers

After completing and merging a feature branch into the main branch, what is the recommended next step concerning the feature branch itself?

<p>Delete the local and remote feature branch to keep the repository clean. (B)</p> Signup and view all the answers

A developer accidentally made a commit to the wrong branch. What is the recommended approach to rectify this situation?

<p>Cherry-pick the commit onto the correct branch and then remove it from the incorrect branch. (C)</p> Signup and view all the answers

A developer needs to temporarily save changes without committing them because they need to switch to a different task. Which Git command should they use?

<p><code>git stash</code> (B)</p> Signup and view all the answers

Flashcards

Git

A version control system for tracking changes in computer files and coordinating work on those files among multiple people.

GitHub

A web-based platform for version control using Git. It offers collaboration features, issue tracking, and more.

Git Workflow

The overall process of managing code changes using Git, from development to deployment.

Centralized Workflow

A Git workflow where all developers push changes to a single, central repository.

Signup and view all the flashcards

Feature Branching

A workflow where each feature or task is developed in its own isolated branch.

Signup and view all the flashcards

Gitflow Workflow

A strict branching model designed for managing large projects, with main, develop, feature, release, and hotfix branches.

Signup and view all the flashcards

Forking Workflow

A workflow popular in open-source projects where contributors create their own copy of the repository, make changes, and propose them as pull requests.

Signup and view all the flashcards

Hotfix Branch

A branch used to quickly patch urgent issues in the production code.

Signup and view all the flashcards

GitHub Repository

A shared online space for code, where teams can collaborate on projects.

Signup and view all the flashcards

Feature Branch

A copy of the main project, used to develop new features or fix bugs without affecting the main codebase.

Signup and view all the flashcards

Pull Request (PR)

A request to merge changes from a branch into the main project. It allows for code review before integration.

Signup and view all the flashcards

Branch Protection Rule

Rules to protect important branches (like 'main') by requiring reviews and preventing direct commits.

Signup and view all the flashcards

Git Push

Moving saved changes from your local computer to the online repository.

Signup and view all the flashcards

Git Pull

Bringing the latest changes from the online repository to your local computer..

Signup and view all the flashcards

Git Merge

Combining changes from one branch into another.

Signup and view all the flashcards

Git Rebase

A way to integrate changes from one branch into another by rewriting the commit history. It creates a cleaner history but can be risky

Signup and view all the flashcards

Study Notes

  • Common Git workflows include Centralized Workflow, Feature Branching, Gitflow Workflow, and Forking Workflow.

Centralized Workflow

  • Treats a single repository (often the main branch) as the central authority, similar to traditional version control systems like SVN.
  • Developers clone the repository, make changes locally, and directly push to the central repository, often without extensive branching.
  • git push origin main will push changes to the remote repository.
  • git pull --rebase origin main will update local repository with remote changes.

Gitflow Workflow

  • A structured branching model with main and develop as the two main branches, as well as supporting branches for features, releases, and hotfixes.
  • Developer workflow: create feature branches from develop, merge back after completion, create release branches for finalizing versions, and hotfix branches for urgent patches to production.
  • Branches of the workflow include:
    • master (or main): stores the currently released version of code.
    • develop: stores a copy of the main branch with all additional changes that have been added after the last release.
    • feature: branches created by developers off of the develop branch for new features.
    • hotfix: branches used to quickly patch production releases and fork directly off of main/master.
    • Branch names are generally named based on the change made. Ex. bug/StackOverflowFixInService or task/PRJ-1234-AddCardPage.

Forking Workflow

  • Common in open-source projects.
  • Contributors fork the central repository into their accounts, make changes in their forks, and submit pull requests to propose changes to the original repository.

Feature Branching

  • Involves creating a separate branch for each new feature or task.
  • Developers work on isolated branches, and, once complete and reviewed, the feature branch is merged back into the main or development branch.

Preparing for Github Usage

  • Select someone in the team to be responsible for GitHub.
  • The selected person creates a repository on GitHub and invites other members.
  • Need to protect key branches.
  • Must not forget the .gitignore file.

Adding Github Collaborators

  • Invite team members to collaborate.
  • Team members must accept the invitations.

Branch Protection Rule

  • Protect the main branch (main/master).
  • Can only update commits to the main branch with pull requests.
  • State how many people must approve a pull request.

Git Workflow

  • The workflow includes the following steps:
    • If you do not have the repository cloned locally, clone it from GitHub git clone <repository-url>.
    • Navigate to the repository directory using the command cd <repository-url>.
    • If there is a repository, ensure you are on the main brach: git switch main.
    • Pull the latest changes from the remote main branch to sync with git pull origin main.
    • Creates a new branch when a job is started and it is pulled from Jira: git switch -c Task-123.

Develop Locally

  • Stage changes via git add .
  • Commit changes with a message git commit -m "Implement feature X as per TASK-123".
  • Update the branch before pushing, or merge git fetch orogin or git merge origin/main.

Resolve Conflicts

  • Conflicts must be resolved if they arise after merging. Command: git add <resolved-files> and git commit.
  • An alternative to merging is Rebasing git rebase origin/main.

Merge vs Rebase

  • Merge: merging an existing branch with the specified brach.
  • Rebase: merging with the specification to rewrite the branch's commits so they appear to be started from another branch.
    • Often used to keep projects more organized.
    • Needs to be performed with care, as the record history is being altered.

Pushing a Feature Branch

  • To push a feature, use the command $ git push origin TASK-123.

Pull Requests

  • Then, create a pull request.
  • PRs have to be reviewed and if necessary, modified and committed.
  • Afterwards, the PR has to get merged into the development branch.
  • Return to the main branch and pull new changes with git pull origin development.
  • Delete the feature branch (git branch -d TASK-123).
  • Delete the feature branch from the remote repository.
  • Run git fetch --prune to clean up stale references.
  • To add the feature in future, ensure that you are o the main branch (git switch main).
  • To create a new feature, replace with the correct names git switch -c TASK-456.

Useful commands

  • git stash to temporarily store all modified tracked files and changes to allow switching branches.
  • Use $ git reset --soft HEAD~1 to undo the last commit but maintain the changes in the working directory.

Studying That Suits You

Use AI to generate personalized quizzes and flashcards to suit your learning preferences.

Quiz Team

Related Documents

GitHub Workflow Tutorial PDF

More Like This

Use Quizgecko on...
Browser
Browser