Skip to content
Marie-Louise edited this page Feb 7, 2019 · 34 revisions

Basics

General

move back one directory

$ cd ..

check status

$ git status

to add updated files

$ git add <file_path>

to undo git add and remove file from staging

$ git reset <file_path>

to save changes and add a comment

$ git commit -m "<first commit>"

To show file the differences of files not yet staged

$ git diff

To show differences between staged files and the last file version

$ git diff --staged

to check the differences between branches

$ git diff <branch_name> <other_branch_name>

to see the history of activity/ git commands on that branch

$ history

to see the last 10 commands

$ history 10

Update master branch

$ git checkout master

$ git fetch origin -p

$ git reset --hard origin/master

$ git log

NOTE:

$ git fetch origin 

can be executed on any branch

Create repositories

to create a new repo

$ git init <project_name>

to download an existing repo with it's version history

$ git clone <URL>

Branch

create new branch

$ git checkout -b <local_branch_name>

delete branch

$ git branch -d <local_branch_name>

display full list of git branches

$ git branch -a

to check current branch

$ git branch

Push local branch

$ git push origin <local_branch_name>

view the history

$ git log

Switch branches

$ git checkout <local_branch_name>

Remove file from staging

$ git rm <file_name>

Remove node modules from staging

$ git rm -r --cached node_modules/

Cheat Sheet

Git Cheat Sheet

Other

Setting up Drupal environment in AWS

GitHub

creating a new remote repository

create a new repo in the git UI, don't click add readme.md

In the terminal type mkdir <name> in the Sites directory ....

find …or push an existing repository from the command line in gitHub and paste the whole line into your directory

the run git push -u origin master

Fatal: remote origin already exists

run

git remote rm origin

the run

git remote add myorigin git@github.com:myname/oldrep.git (find this on gitHub under …or create a new repository on the command line)

Clone this wiki locally