Giter Club home page Giter Club logo

git_branching_cheatsheet_porta's Introduction

Git Branching

Branching allows us to collaborate on projects and help keep our code base stable.

Common Tasks

  • git branch BRANCH-NAME - Create a branch with the name of BRANCH-NAME
  • git branch - Display the branch you're currently on
  • git branch -a - Show all available branches that have been created
  • git checkout BRANCH-NAME - Switch to the branch with name BRANCH-NAME
  • git merge --no-ff BRANCH-NAME - Merge BRANCH-NAME into the current branch (use git branch to determine the current branch)
  • git pull origin BRANCH-NAME - Pull down changes from the remote
  • git checkout -b BRANCH-NAME - Combines branch creation with checkout in one handy command

Common Branches

master

The master branch generally contains fully tested code that can be deployed. This is generally used as the starting point for individual projects. The master branch is what you have been working with to date, it's created by default.

feature_NAME

When working on a task, you will want to create a branch for the feature that you are working on. The feature will be created using the branch you're currently on as a starting point. Let's assume we're on the master branch and creating a feature of feature-login-html.

Create the feature-login-html branch

git branch feature-login-html
⍟ master
|
|\
| o feature-login-html

Switch to the feature-login-html branch

git checkout feature-login-html
o master
|
|\
| ⍟ feature-login-html

Make some changes and commit them

Update the code in your files.

git add .
git commit -m "COMMIT MESSAGE"
git push origin feature-login-html
o master
|
|\
| o feature-login-html
| |
| ⍟ commit "COMMIT MESSAGE" (still on feature-login-html)

At this point you can continue making commits.

Merge your changes back into master (happy path)

Go back to master

git checkout master
⍟ master
|
|\
| o feature-login-html
| |
| o commit "COMMIT MESSAGE" (still on feature-login-html)

Merge from feature-login-html into master

git merge --no-ff feature-login-html
o master
|
|\
| o feature-login-html
| |
| o commit "COMMIT MESSAGE" (still on feature-login-html)
|/
⍟ <- We are now here

Git Branching Diagram

develop

The develop branch gives us a safety net when working with teams. This is generally used as the starting point for group projects but for now we'll stick with master.

VIM

To exit VIM, press shift and :, type wq and press enter.

You can configure git to use a different Terminal text editor if you get tired of this arcane editor.

$ git config --global core.editor your-editor-here

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.