Giter VIP home page Giter VIP logo

git-cheatsheet's Introduction

Git-CheatSheet

Getting Started

Installation

Download git and install from https://git-scm.com/downloads

Configuring the user information

git config --global user.name "[name]"
git config --global user.email "[email address]"
git config --global color.ui auto

Stage & Snapshot

git clone https_url

# Checking the list of remote and local branchs
git branch -a
    
# Checking the list of Only remote branchs
git branch -r
  
# Checking the list of Only local branchs
git branch

# Creating and check out in a local branch
git checkout -b local_branch_name_1

# After making changes and checking updates in my current branch
git status

# See the difference here and press 'q' to get out
git diff

# Add all changes in the commit history
git add .

# Or we can Add specific changed files in the commit history
git add <file_url.type>

# We can reset back to Head of a specific file
git reset <file_url.type>

# commiting updates for the local branch
git commit -m "updates"

# pushing local branch
git push

# pushing local branch and set the remote as upstream
git push --set-upstream origin local_dev1

# Or to checkout a remote branch
git checkout remote_branch_name

# Now pushing to another remote branch
git push origin remote_branch_where_I_want_to_push

# fetching is prefereable
git fetch

# Now pull from another remote branch
git pull origin remote_branch_where_I_want_to_pull

# Now resolve the conflicts and do merge in the local_branch then add all and commit as merging conflict resolve and then just push
git add .
git commit -m "merge conflict resolve"
git push

Stashing/ Temporary Commits

# Stashing is basically used while we got to pull from a branch but we don't want to lose our changes and don't want to commit and push them. So by saving the changes locally in a stack and popping them we can get them back again.

#check the changes
git status

#don't want to lose the changes but have to pull from a branch. So, lets just stash them with a message
git stash push -m "my_new_stash"
git pull origin another_remote_branch

#checking the list of stashs
git stash list

#popping stash@{0} to commit 
git stash pop

#clearing all the stashes
git stash clear

Multiple Stashing

git stash push -m "my_new_stash"
git pull origin another_remote_branch

#after resolving the conflicts, push to merge locally
git push

#make changes without popping the stash and need to pull again
git stash push -m "another_new_stash"

#check your list of stashs, we will have 2 stashs
#shash@{0}: on local_dev_branch : my_new_stash
#shash@{1}: on local_dev_branch : another_new_stash
git stash list

#now pull, resolve conflict, push again and then pop a specific stash. But stash pop will apply exactly stash@{0}.
git stash apply stash@{n}

#now drop specific stash
git stash drop stash@{n}

git-cheatsheet's People

Contributors

tareque2208 avatar

Watchers

James Cloos avatar  avatar

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.