GIT Guide: Initial Configuration
GIT Guide: Initial Configuration
GIT Guide: Initial Configuration
GIT Guide
Initial configuration
To set user information:
1. git init
2. git config user.name "someone"
3. git config user.email "someone@someplace.com"
4. git add *
5. git commit -m "some init msg"
Basic commands
Use Git commands to help keep track of changes made to a project:
git add adds files from the working directory to the staging area
o In order to start tracking a file, add it to Stage Area by git add <filename>
o More files can be added git add <filename1> <filename2>
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
o –m to add a message related to the commitment status, btw quotation marks
Repository structure
A Git project can be thought of as having three parts:
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
Workflow
1. Edit file in the Working directory
2. Add file to Staging area
3. Save changes to Repository
Backtrack
git checkout HEAD <filename>: Discards changes in the working directory.
git reset HEAD <filename>: unstages file changes in the staging area.
git reset <commit_SHA>: Resets to a previous commit in your commit history.
1. Remove the modified <filename> from the staging area and bring back at Working Directory, where
it keeps the modifications done after committing
2. Reset the file <filename> in staging area to the version after in HEAD commit
Branching
Git allows us to create branches to experiment with versions of a project.
git branch checks what branch you are currently on, which is indicated with * asterisk
git branch new_branch creates a new branch. The master and fencing branches are identical: they
share the same exact commit history
git checkout new_branch is used to switch to the new branch
The normal operations can be done to files (add, commit) but they are applied to the new_branch
git branch -d new_branch will delete new_branch
Andrea Cremasco
A remote is a shared Git repository that allows multiple collaborators to work on the same Git project from
different locations. Collaborators work on the project independently, and merge changes together when
they are ready to do so.
Typical workflow
1. Fetch and merge changes from the remote
git fetch
This command will not merge changes from the remote into your local repository. It brings those
changes onto what's called a remote branch origin/master. Your local master branch has not been
updated yet, so you can't view or make changes to any of the work she has added.
2. Merge remote branch to master local
git merge origin/master
3. Create a branch to work on a new project feature
4. Develop the feature on your branch and commit your work
Andrea Cremasco
5. Optional: Fetch and merge from the remote again (in case new commits were made while you were
working)
6. Push your branch up to the remote for review
git push origin branch_name
Github
Git projects are usually managed on Github, a website that hosts Git projects for millions of users. With
Github you can access your projects from anywhere in the world by using the basic workflow you learned
here.