Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
3 views4 pages

Git Cheat Sheet - Branching Strategy

Uploaded by

chandankrs132
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views4 pages

Git Cheat Sheet - Branching Strategy

Uploaded by

chandankrs132
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

CONTENTS

[ Like and Subscribe ]

1) GIT CHEAT SHEET


2) REAL TIME BRANCHING STRATEGY
3) INTERVIEW Q&A

6 Painful Git Interview Questions and Answers You need to know


Q1: What is Git fork? What is the difference between fork, branch and clone?

A fork is a remote, server-side copy of a repository, distinct from the original. A fork isn't a Git
concept really, it's more a political/social idea.
A clone is not a fork; a clone is a local copy of some remote repository. When you clone, you are
actually copying the entire source repository, including all the history and branches.
A branch is a mechanism to handle the changes within a single repository in order to eventually
merge them with the rest of code. A branch is something that is within a repository. Conceptually,
it represents a thread of development.

Q2: What's the difference between a "pull request" and a "branch"?

A branch is just a separate version of the code.


A pull request is when someone take the repository, makes their own branch, does some
changes, then tries to merge that branch in (put their changes in the other person's code
repository).

Q3: How to revert previous commit in git?

git reset --hard HEAD~1


git reset HEAD~1
git reset --soft HEAD~1

Q4: What is "git cherry-pick"?

The command git cherry-pick is typically used to introduce particular commits from one branch
within a repository onto a different branch. A common use is to forward- or back-port commits
from a maintenance branch to a development branch.

git cherry-pick <commit-hash>

Q5: Explain the advantages of Forking Workflow

The Forking Workflow is fundamentally different than other popular Git workflows. Instead of
using a single server-side repository to act as the “central” codebase, it gives every developer
their own server-side repository. The Forking Workflow is most often seen in public open source
projects.

Q6: Could you explain the Gitflow workflow?


Master - is always ready to be released on LIVE, with everything fully tested and approved
(production-ready).
Hotfix - Maintenance or “hotfix” branches are used to quickly patch production releases. Hotfix
branches are a lot like release branches and feature branches except they're based on master
instead of develop.
Develop - is the branch to which all feature branches are merged and where all tests are
performed. Only when everything’s been thoroughly checked and fixed it can be merged to the
master.
Feature - Each new feature should reside in its own branch, which can be pushed to the develop
branch as their parent one.

git init: Initializes a new Git repository in the current directory.


git clone <url>: Clones an existing Git repository from a URL.
git add <file>: Adds a file to the staging area.
git commit -m "<message>": Commits changes to the repository with a message.
git status: Shows the current state of the working directory and staging area.
git diff: Shows the differences between the working directory and the staging area, or
between the staging area and the last commit.
git log: Shows the commit history of the repository.
2. Branching and Merging
git branch: Lists all local branches.
git branch <branch_name>: Creates a new branch.
git checkout <branch_name>: Switches to a different branch.
git checkout -b <branch_name>: Creates a new branch and switches to it.
git merge <branch_name>: Merges the specified branch into the current branch.
3. Remote Repositories
git remote add origin <url>: Adds a remote repository named "origin".
git push origin <branch_name>: Pushes the current branch to the remote repository.
git pull origin <branch_name>: Pulls changes from the remote repository.
4. Other Useful Commands
git reset --hard HEAD^: Reverts the last commit.
git stash: Temporarily saves changes to the working directory.
git stash pop: Restores the most recently stashed changes.
git tag <tag_name>: Creates a tag for a specific commit.
Tips for Using Git
Write clear commit messages. This helps you and others understand the changes you've
made.
Use branches for new features or bug fixes. This allows you to work on multiple things at
once without affecting the main codebase.
Commit often. This makes it easier to revert changes if necessary.
Use a version control system like GitHub or GitLab to collaborate with others.

You might also like