Git Source Control
Introduction
Working directory
Staging area
Repository
Basic Git Commands
Starting with a Fresh Project
Create a folder called “fresh-project” and initialize a new repository:
` git init fresh-project `
Get the status of the Git repository:
` git status `
“untracked files”: Git is not tracking the file yet.
To have Git track the file, we need to add that file to the Git index, or to Git staging area by:
` git add filename `
“Changes to be committed”: the new file is in the Git staging area (waiting to be committed, but not committed yet).
Commit:
` git commit `
Adding Git to an Existing Project
Initialize a new repository using the current folder:
` git init `
All all files ar once to Git staging area:
` git add . `
Commit with a message inline:
` git commit -m “message” `
Pull and Push
We need to push any changes, actually local commits up tp our remote repository.
Update repository with any changes that may have happened on the remote repository:
` git pull origin master `
Always doing a pull before doing a push.
Push any commits from the local repository to the remote repository:
` git push origin master `
“origin” is the name of the remote repository. “master” is the master branch.
Tracked Files
Shortcut the add and commit process into one step:
` git commit -am “message” `
The above action can only been done with the files that are being tracked. A tracked file is any file tht Git is aware of and tracking actively. That would be any file that has been committed into the Git repository or any file that has been added to the Git index, or the Git staging area.
Find out if the file is being tracked by Git:
` git ls-files `
Editing Files
One of the main points of the staging area is that we build up our changes for the commit
` git add filename `
` git commit -m “message” `
Recursive Add
` git add . `
Backing Out Changes (Unstage)
` git reset HEAD filename `