git Cheat Sheet

My super concise git notes

Developed by Linus Torvalds, git is a…

  1. Distributed Version Control System (VCS) for any type of file
  2. Co-ordinates work between multiple developers
  3. Tracks who made what changes and when
  4. Revert back at any time
  5. Supports local and remote repositories (hosted on github, bitbucket)

It keeps track of code history and takes snapshots of your files
You decide when to take a snapshot by making a commit
You can visit any snapshot at any time
You can stage files before committing

INSTALLING git
sudo apt-get install git (debian)
sudo yum install git (red hat)
https://git.scm.com (installers for mac and windows)
gitbash is a linux-like command cli for windows

CONFIGURING git
git config –global user.name ‘matt bradley’
git config –global user.email ‘matt@cyberfella.co.uk’
touch .gitignore
echo “log.txt” >> .gitignore
Add file to be ignored by git, e.g. log file generated by script
echo “/log” >> .gitignore Add directory to be ignored, e.g. log directory

BASIC COMMANDS (local repository)
git init Initialize a local git repository (creates a hidden .git subdirectory in the directory)
git add Adds file(s) to Index and Staging area ready for commit.
git add . Adds all files in directory to Staging area
git status check status of working tree, show files in Staging area and any untracked files you still need to add
git commit commit changes in index – takes files in staging are and puts them in local repository
git commit -m ‘my comment’ Skips git editing stage adding comment from command.
git rm –cached removes from staging area (untracked/unstaged).

BASIC COMMANDS (remote repo)
git push push files to remote repository
git pull pull latest version from remote repo
git clone clone repo into a local directory

git clone https://github.com/cyberfella/cyberfella.git clones my cyberfella repository

git –version shows version of git installed

BRANCHES
git branch loginarea creates a branch from master called “loginarea”
git checkout loginarea switches to the “loginarea” branch
git checkout master switches back to the master branch version
git merge ‘loginarea’ merges changes made to ‘loginarea’ files in loginarea branch to master branch

REMOTE REPOSITORY
https://github.com/new
Create a public or private repository
Shows the commands required to create a new repository on the command line or push an existing repository from the command line

README.md
A readme.md (markdown format) file displays nicely in github.

#MyApp

This is my app

Basically it should look like this in github

MyApp

This is my app

USEFUL COMPLIMENTARY INFORMATION

atom is a very nice, simple text editor for programmers that supports integration with git. https://flight-manual.atom.io/getting-started/sections/installing-atom/

image_pdfCreate PDF of this post...
Facebooktwitterredditpinterestlinkedinmail

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.