GIT (to practice git “try.git.io"
======================
Setup:
One time system setup:
git config —global user.name <username>
git config —global user.email test.user@gmail.com
git config —global push.default matching (for forward compatibility, optional)
git config —global alias.co checkout (This aliases checkout to co, optional)
Note: these settings are saved globally in the "/home/<username>/.gitconfig” file
Step 1) Creating a github repository and connecting it to your project.
NOTE: you need to create a project repository on the github website then add remote target to git.
on the github web site: "+New Repository” enter <projectname>
on the local machine in the <projectname> directory
git remote add origin https://github.com/<username>/<projetname>.git
The previous line adds the following to the "<projectname>/.git/config” file.
[remote "origen"]
url = https://github.com/<username>/sample_app.git
fetch = +refs/heads/*:refs/remotes/origen/*
[branch "master"]
remote = origen
merge = refs/heads/master
Step 2) Initializing and synchronizing the project
initialize git: (use this the first time for each project)
cd <project root directory>
git init (Create an empty git repository or reinitialize a current one)
git add -A (Adds all of the files in the current directory to a staging area {except what is in .gitignore})
git status (view files in staging area)
git commit -a -m “My log message goes here” (commit the changes to the repository {NOTE: local only})
-m “” lets you add a message to each commit. You can view the commit messages using "git log”
-a (be careful with the ‘-a’ this adds all changed files and commits them. This may or may not be what you want_
git add . (USE THIS VERY CAREFULLY AND NOT MUCH!!!!, This will add all data including images to your commit)
git push -u origin master (this will fail if you did not set up the github repository)
Branching
—————
git checkout -b branch-a (This creates a new branch named “branch-a” and puts code into it)
git branch (This lists all of the current branches)
* branch-a
master
git checkout master (Return to the master branch, Master is used for known working code. Do not post in progress code to this branch)
git diff branch-a (This will compare the files in the master branch with the files in the “branch-a” branch and show you the difference)
To Delete a Branch
————————-
git branch -d branch-a (This will delete a branch ONLY if it has been merged, Use -D if you want to deleted regardless of merge state)
To save a work in progress if you need to go work on something else:
————————————————————————————————
git checkout -b branch-b
git commit -am “WIP: This is a work in progress, needed to work on patch on master”
git checkout master
Tweak app
git commit -am “Fix to master done”
git checkout branch-b
To merge the branches, navigate to the branch you want code MOVED INTO and run merge:
————————————————————————————————————————
git checkout master
git merge branch-b -m “Merged branch-b features with master"
GitFlow
——————
Produces a diagram of the flow of the get matenence.
Git Tree
———————
git tree
edit you .gitconfig and add this to the bottom
nano ~/.gitconf
tree = log —graph —decorate -oneline —all —color