Skip to content

Latest commit

 

History

History
415 lines (295 loc) · 5.77 KB

commands.md

File metadata and controls

415 lines (295 loc) · 5.77 KB

Commands for the codebar git workshop

Copy and paste the following commands in the terminal to follow along with the slides

Part 1

The command line

Slide 10:


whoami
ls -al

Configuration

Slide 12:

Configure git with your name and email. Replace "Your name" and "[email protected]" in the commands below with your name and email address


git config --global user.name "Your name"
git config --global user.email "[email protected]"

Git Init

Slide 13:

Make a new git repository

cd

on windows...

cd "My Documents"

on mac...

cd Documents
mkdir my-repo
cd my-repo
git init

Slide 14:

ls -al
ls -al .git

Our first command

Slide 15:

Git status shows the current state of changes

git status

Git add

Slide 20:

Create a file README.txt in the directory. Then add it to git

git add README.txt
git status

Our first commit

Slide 23:

Commit our new file

git commit -m "My first commit"
git log

Editing a file

Slide 25:

Make an edit to Readme.txt and then check the status

git status
git diff

Git add and commit

Slide 26:

git add README.txt
git commit -m "Edited Readme"

Removing files

Slide 27:

Remove a file tracked in git

git rm README.txt
git status
git commit -m "Removed readme"

History

Slide 28:

Git log will give you a list of commits in reverse order.

If git log fits on more than one terminal screen it will go into a scrolling mode. press spacebar to scroll down a page, and when you get to the end press q to exit.

git log

Part 2

Master

Slide 34:

git status

Git branch

Slide 35:

git branch mybranch
git branch

Checkout

Slide 36:

git checkout mybranch
touch mybranch.txt
git add mybranch.txt
git commit -m "commit on mybranch"
git log

Parallel branches

Slide 37:

git checkout master
git log

Vice versa

Slide 38:

touch master.txt
git add master.txt
git commit -m "commit on master"
git checkout mybranch
git log

Github

Slide 43:

The repo is at:

https://repo.gitforthe.win

or the full github url is

https://github.com/ocastastudios/codebar-git-workshop

Git clone

Slide 44:

Clone the repository for this afternoon

cd ..
git clone https://github.com/ocastastudios/codebar-git-workshop.git

Cloned repository

Let's look at the repository.

If git log fits on more than one terminal screen it will go into a scrolling mode. press spacebar to scroll down a page, and when you get to the end press q to exit.

Slide 45:

cd codebar-git-workshop
git status
git log

Git fetch

Slide 49:

git fetch
git status

Git pull

Slide 50:

git pull

Pushing

Slide 51:

In the commands below, change myname to your actual name (for example danielvanberzon)

git branch myname
git checkout myname

Make a commit

Slide 52:

Don't forget to change myname in the commands below to your name

touch myname.txt
git add myname.txt
git commit -m "branch commit"

Git push

Slide 53:

Don't forget to change myname in the command below to your name

git push -u origin myname

Pushed to github

Slide 54:

Don't forget to change myname in the command below to your name

git rm myname.txt
git commit -m "branch commit 2"
git push

Git merge

Slide 59:

Go back into my-repo and list branches

cd ..
cd my-repo
git branch

Part 3

Git merge

Slide 60:

Merge mybranch into master --no-edit means we don't have to create a merge commit message

git checkout master
git merge mybranch --no-edit.

Merged branch

Slide 61:

If git log fits on more than one terminal screen it will go into a scrolling mode. press spacebar to scroll down a page, and when you get to the end press q to exit.

git log

Afternoon:

Useful git commands for the afternoon

Here is a list of useful git commands for when you are working on the afternoon exercise.

If the command has a word in angle brackets, e.g <filename> you should replace this with the appropriate name.

For example, if you want to add the file README.txt, the command git add <filename> should become git add README.txt

  • View the current status

    git status
    
  • View any un added changes

    git diff
    
  • Add a file to the index

    git add <filename>
    
  • Remove a file and add the deletion into the index

    git rm <filename>
    
  • Make a commit

    git commit -m "<message>"
    
  • See the commit history

    git log
    

    If git log fits on more than one terminal screen it will go into a scrolling mode. press spacebar to scroll down a page, and when you get to the end press q to exit.

  • List the branches

    git branch
    
  • Create a branch

    git branch <branchname>
    
  • Checkout onto a branch

    git checkout <branchname>
    
  • Retrieve latest commit info from the remote repository

    git fetch
    
  • Pull latest commits for a branch from the remote repository

    git pull
    
  • Push a branch for the first time to the remote repository

    git push -u origin <branchname>
    
  • Push a branch that's already been pushed once

    git push
    
  • Lookup instructions on how to use a command

    git <command> --help
    

    E.G git checkout --help