image info

Why Git?

  • Collaboration
  • Personal Portfolio

Collaboration

Personal Portfolio

Layers of git

Layers of git

image info

Installed?

Configured?

git config --global user.name "John Doe"
git config --global user.email johndoe@example.com

Let’s get started

Let’s get started

  • git clone
  • git init

Let’s get started

$ git clone

image info

Let’s get started

$ git init

image info

Let’s get started

$ git init
$ git remote add origin https://github.com/personalRepo

image info

Let’s get started

A new repository gives you the commands to do this…

image info

Let’s get started

…or create a new repository on the command line

echo "# <repo>" >> README.md
git init
git add README.md
git commit -m "first commit"
git branch -M main
git remote add origin https://github.com/<user>/<repo>.git
git push -u origin main

…or push an existing repository from the command line

git remote add origin https://github.com/<user>/<repo>.git
git branch -M main
git push -u origin main

You wrote code!

And now you are ready to push your code!

What are the steps?

### add individual file
$ git add file1
### or add all changed files
$ git add .

image info

### commit your files
$ git commit -m "A message about your push"

### without the -m your default editor will open
### this will allow you to type a longer message
$ git commit 

image info

### push your files
$ git push

image info

Put it all together

### Add your files to the staging area
git add .

### commit your files to you local repository
git commit -m "Meaningful message here"

### push your files to the remote repository
$ git push

git branch

Branches allow independent lines of development.

image info

### create a branch
$ git branch <branch-name>
### list available local branches
$ git branch
### list remote branches only 
$ git branch -r
### list both local and remote branches
$ git branch -a
### switch to <branch-name>
$ git checkout <branch-name>
### create and switch to branch in one step
$ git checkout -b <branch-name>

git branch

It is best practice when collaborating to do new development in a branch. Using github this will allow you to use the most important feature of collaborating. The code review.

Let’s go over this.

### get the latest code from your repo
$ git pull
### create a branch and move to it
$ git branch <branch-name>
### Create code change
$ git add .
$ git commit -m <your message>
### push code to remote in new branch
$ git push --set-upstream origin <branch-name>

This will create your code change in a branch on the remote repository.

This will allow you to create a “pull request” which is the review process for the new code to be merged into the master branch.

The pull request can be done inside github.

image info

image info

image info

Other useful commands.

### merge current-branch with <branch-name>
### Keeps history of both branches
$ git merge <branch-name>

### If conflicts happen, resolve add, and continue
$ git add . 
$ git merge --continue
###  merge current-branch with <branch-name>
### Removes history 
$ git rebase <branch-name>

### If conflicts happen, resolve add, and continue
$ git add . 
$ git rebase --continue

###  pulls remote and rebase 
$ git pull --rebase

Other useful commands.

###  to temporarily store working changes
$ git stash

### re-apply the changes that have been stashed
$ git stash apply
### see what files are different
$ git status

### list the differences in a file
$ git diff <file-name>

### See commit history
$ git log

Have Fun!

Helpful links: