learn Git in 15 minutes
Git Workflow
git init
The word init means initialize.
The command sets up all the tools Git needs to begin tracking changes made to the project.
A Working Directory: where you'll be doing all the work: creating, editing, deleting and organizing files
A Staging Area: where you'll list changes you make to the working directory
A Repository: where Git permanently stores those changes as different versions of the project
The Git workflow consists of editing files in the working directory, adding files to the staging area, and saving changes to a Git repository.
In Git, we save changes with a commit.
git status
Check the status of changes:
git status
git add
In order for Git to start tracking scene-1.txt, the file needs to be added to the staging area.
We can add a file to the staging area with:
git add filename
The word filename here refers to the name of the file you are editing, such as scene-1.txt.
git diff
we can check the differences between the working directory and the staging area with:
git diff filename
git commit
A commit is the last step in our Git workflow. A commit permanently stores changes from the staging area inside the repository.
git commit -m "Complete first line of dialogue"
Standard Conventions for Commit Messages:
Must be in quotation marks
Written in the present tense
Should be brief (50 characters or less) when using -m
git log
Often with Git, you'll need to refer back to an earlier version of a project. Commits are stored chronologically in the repository and can be viewed with:
Generalizations
git init creates a new Git repository
git status inspects the contents of the working directory and staging area
git add adds files from the working directory to the staging area
git diff shows the difference between the working directory and the staging area
git commit permanently stores file changes from the staging area in the repository
git log shows a list of all previous commits
This command takes a remote name and a repository URL, which in your case is https://github.com/try-git/try_git.git.
git remote add
git remote add origin https://github.com/try-git/try_git.git
git remote add new https://github.com/williamkpchan/williamkpchan.github.io
Pushing Remotely
The push command tells Git where to put our commits.
The name of our remote is origin and the default local branch name is master. The -u tells Git to remember the parameters, so that next time we can simply run git push and Git will know what to do.
git push -u origin master
We can check for changes on our GitHub repository and pull down any new changes by running:
git pull origin master
Take a look at what is different from our last commit by using the git diff command.
In this case we want the diff of our most recent commit, which we can refer to using the HEAD pointer.
git diff HEAD
Another great use for diff is looking at changes within files that have already been staged.
git diff with the --staged option to see the changes you just staged.
git diff --staged
You can unstage files by using the git reset command.
git reset octofamily/octodog.txt
Files can be changed back to how they were at the last commit by using the command: git checkout --
git checkout -- octocat.txt
Create a copy (aka. branch)
Then done they can merge this branch back into their main master branch.
create a branch called clean_up
git branch clean_up
Switching Branches
you'll see two local branches:
a main branch named master and
new branch named clean_up
switch branches using the git checkout command
git checkout clean_up
Removing All The Things
git rm command which will not only remove the actual files from disk, but will also stage the removal of the files for us.
git rm '*.txt'
Now that you've removed all the cats you'll need to commit your changes.
git commit -m "Remove all the cats"
Switching Back to master
git checkout master
Preparing to Merge
We're already on the master branch, so we just need to tell Git to merge the clean_up branch into it:
git merge clean_up
git branch -d to delete a branch
git branch -d clean_up
Final Push
git push
git remote add origin https://github.com/williamkpchan/williamkpchan.github.io.git
git pull origin master
git push -u origin master
git commit -m "second commit"
git remote set-url origin https://github.com/williamkpchan/williamkpchan.github.io.git