Local Git Repository

  • remember to run in git bash

mkdir foldername

touch filename

code filename (open the file)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// intialize a git repository
git init

// see what's in staging area
// it can also help to see which file has been modified after last commit
git status

// add file to staging area
git add chapter1.txt
git add .

// remove from staging area
git rm --cached -r filename

// commit the files
git commit -m "test"

// see what's been commited
git log

// compare the difference between working area and local repostory
git diff filename


// roll back to the previous version that was committed in our local repository
git checkout chapter3.txt

Remote Repository

1
2
3
4
5
6
7
// create the remote
git remote add origin https://github.com/DanLovPotato/Test.git

//push local repository to remote repository
// u option is to link up your remote and local repositories
// origin is the name of remote and master is the name of branch
git push -u origin master

Git Ignore(do this before git add)

1
2
3
4
5
6
7
8
touch .gitignore// you put the file names that you dont want to upload in here


in gitignore:

secrets.txt (filename)
# comment (comment)
*.txt (all the txt file wont be uploaded)

https://github.com/github/gitignore here’s some templates of gitignore templates for different types of projects.

you usually want to ignore those user related files that are not going to be useful to your collaborators.

Git Clone

1
git clone https://github.com/austinzheng/swift-2048.git

Branching and Merging

1
2
3
4
5
6
7
8
9
10
11
12
// create new branch
git branch name

// see what branches you have, and what branch you are on
git branch

// switch to the branch
git checkout name

git merge branchname

git push origin master -u

in git log:

(HEAD -> master) is local repository

(origin/master) is remote repository