All the commands you see below need to be executed in a Terminal (Mac or Linux) or Git Bash (Windows)
First things first, configure Git from the command line:
Make sure to replace [NAME] with your full name, and [EMAIL] with the email address registered in your GitHub account
git config --global user.name "[NAME]"
git config --global user.email "[EMAIL]"
git config --global color.ui auto
git config --global push.default simple
You can probably understand what the first 2 lines do, but what about the last 2?
Check your Present Working Directory:
pwd
List the contents of the directory:
ls -la
Cool, now go back to your browser and browse to the short URL on the whiteboard in front of you.
You'll need to "fork" this repository (what does forking mean?)
After you successfully fork the repo, click on the green "Clone or Download" button. You'll see a URL and a button next to it that says "Copy to Clipboard". Guess what you gonna do? Oh My God! You are AMAZING! and yes, just click on the copy button and go back to your terminal / git bash window
Let's clone the repo we just forked (paste the URL you copied instead of the [ADDRESS] part):
git clone [ADDRESS]
List the contents of the directory now, you still remember how to do that, right?
Confirm that you have 2 .md file and a "names" directory
This cloned all the contents of the selected repo into a directory of the same name.
Let's change our present working directory into the repo we just cloned:
cd git_workshop_2016
Check which "remotes" do you have in the repo you just cloned:
Don't worry if you don't understand this now, you'll get why we checked this later
git remote -v
Change your present working directory into "names":
cd names
Create a text file and inserts a number into it.
Replace [NUMBER] with a random number of your choice.
Replace [NAME] with your initial & last name.
echo "[NUMBER]" > [NAME].txt
List the contents of your directory to ensure that a text file with your name was created.
Try to display the contents of the file from the command line.
Go up one level into the parent directory (the repo we cloned):
cd ..
Let's check what Git believes has changed in the repo:
git status
What do you understand from the "status" command? Let's discuss it.
Let's add the file we created into Git staging area.
Actually, let's add everything in our directory (including all files and sub-directories) into the staging area:
git add .
Check Git status again, what has changed?
Seems like we're ready to commit the changes. Let's do that:
git commit -m "Added my name in a text file!"
What do you think "-m" option is for?
Now, let's push the changes we made into the repo's source (GitHub):
git push
it will probably prompt you for your GitHub credentials, enter your username and password accordingly
Well done! Now pay attention on how we gonna open a "pull request" (what does that even mean?), and how will that work (We'll wait for everyone to get to this step, then Marwan will take it from there, so just sit tight)
So you're comfortable with how the absolute basics & pull requests work? Pat yourself on the shoulder, you had a very good start with Git!
Let's carry on ...
Now, to be able to pull the changes from the original repo (the one you forked out from), we need to add it as an upstream in our remotes list:
git remote add upstream https://github.com/m-alani/git_workshop_2016.git
Check what remotes do you have now and notice what has changed.
Let's fetch the original repo:
git fetch upstream
Now that we synced our repo with upstream "original" repo, let's inspect what happened:
git branch
This command lists the branches you have in your local repo. Notice that the branch with "*" before it is the current active branch.
Did you notice that there is an "upstream/master" branch? Where did that come from? Let's talk about it
Make sure that we are on our local "master" branch:
git checkout master
Finally, let's merge the changes we pulled from the upstream remote (or at least try to):
git merge upstream/master
This brings your local repo up to sync with the remote repo you origiannly forked from.
This also concludes this quick tutorial about Git & GitHub basics!
Time to ask away if you have anything in mind.