Copy and paste the following commands in the terminal to follow along with the slides
Slide 10:
whoami
ls -al
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]"
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
Slide 15:
Git status shows the current state of changes
git status
Slide 20:
Create a file README.txt in the directory. Then add it to git
git add README.txt
git status
Slide 23:
Commit our new file
git commit -m "My first commit"
git log
Slide 25:
Make an edit to Readme.txt and then check the status
git status
git diff
Slide 26:
git add README.txt
git commit -m "Edited Readme"
Slide 27:
Remove a file tracked in git
git rm README.txt
git status
git commit -m "Removed readme"
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
Slide 34:
git status
Slide 35:
git branch mybranch
git branch
Slide 36:
git checkout mybranch
touch mybranch.txt
git add mybranch.txt
git commit -m "commit on mybranch"
git log
Slide 37:
git checkout master
git log
Slide 38:
touch master.txt
git add master.txt
git commit -m "commit on master"
git checkout mybranch
git log
Slide 43:
The repo is at:
or the full github url is
https://github.com/ocastastudios/codebar-git-workshop
Slide 44:
Clone the repository for this afternoon
cd ..
git clone https://github.com/ocastastudios/codebar-git-workshop.git
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
Slide 49:
git fetch
git status
Slide 50:
git pull
Slide 51:
In the commands below, change myname to your actual name (for example danielvanberzon)
git branch myname
git checkout myname
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"
Slide 53:
Don't forget to change myname in the command below to your name
git push -u origin myname
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
Slide 59:
Go back into my-repo and list branches
cd ..
cd my-repo
git branch
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.
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
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 pressq
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