Skip to content

Instantly share code, notes, and snippets.

@Chaitya62
Last active January 21, 2017 06:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Chaitya62/caaa401791539b266a5156fc18eb3878 to your computer and use it in GitHub Desktop.
Save Chaitya62/caaa401791539b266a5156fc18eb3878 to your computer and use it in GitHub Desktop.
Cheat sheet on git for Workshop held on 19/01/17

Git CheatSheet

Installation

On Linux
#Debain Distro
sudo apt-get install git

# Fedora Distro
yum -y install git

On windows and Mac

Download github desktop and shell from here

Getting Started

  	#to initialize git in a local directory
    git init
    
    #to clone a repo from github
    git clone url

Configuring your name and email

	#set up user name
    git config --global user.name "Insert your name here"
    
    #set up user  email
    git config --global user.email "Insert your email here"

Commiting files

Check file status
	git status
how to add files to the staging area
  #add a specific file
  git add filename
 
  #add a specific file type
  git add *.extention
 
  #add all files 
 
  git add .
     or 
  git add *
  
  #this command will unstage the files which are not commited
  git reset filename
How to commit Changes
git commit -m "Insert Commit message here"
See commit history
#detailed commit history
git log
Go back to a previous commit
git reset --hard sha

sha is the alphanumeric you find when using git log

Branches

	# check current branch names
    git branch

	# add a new branch
    git branch branchname
    
    # switch to a different branch
    git checkout branch name
    
    # add a new branch and switch to that branch
   git checkout -b branchname   
   
   # merge a branch to the current branch
   git merge  branchname
Contributing to an Online Repo Workflow

Workflow

Remotes

Manage the set of repositories ("remotes") whose branches you track.

	#check available remotes
    git remote 
    
    #Add a new remote 
    git remote add url
    

Pull and Push

	#pull all the branches from your main repo 
    git pull 
    
    #pull specific branch from a specific repo
    git pull remote-name  branch-name 

	# push all the branches to the main repo
    git push 
    
    #push specific branch to a specific repo
	git push remote-name branch-name    

Resources

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment