1.introduce yourself to Git with your name and public email address before doing any operation
$ git config --global user.name "Your Name Comes Here"
$ git config --global user.email you@yourdomain.example.com
2.Initialized empty Git repository
$ git init
3.tell Git to take a snapshot of the contents of all files under the current directory (note the .)
$ git add .
4.This snapshot is now stored in a temporary staging area which Git calls the "index".
You can permanently store the contents of the index in the repository with git commit:
$ git commit
Alternatively, instead of running git add beforehand, you can use
$ git commit -a
5.Modify some files, then add their updated contents to the index:
$ git add file1 file2 file3
6.You are now ready to commit. You can see what is about to be committed
using git diff with the --cached option:
$ git diff --cached
7.You can also get a brief summary of the situation with git status:
$ git status
8.At any point you can view the history of your changes using
$ git log
You can also give commits names of your own; after running
$ git tag v2.5 1b2e1d63ff
9.A single Git repository can maintain multiple branches of development.
To create a new branch named "experimental", use
$ git branch experimental
10.you’ll get a list of all existing branches:
$ git branch
11.switch to the experimental branch
$ git switch experimental
12.Now edit a file, commit the change, and switch back to the master
branch:
(edit file)
$ git commit -a
$ git switch master
13.You can make a different change on the master branch:
(edit file)
$ git commit -a
14.at this point the two branches have diverged, with different changes made in each.
To merge the changes made in experimental into master, run
$ git merge experimental
15.If the changes don’t conflict, you’re done. If there are conflicts,
markers will be left in the problematic files showing the conflict;
$ git diff
16.will show this. Once you’ve edited the files to resolve the conflicts,
$ git commit -a
17.will commit the result of the merge. Finally,
$ gitk
18.will show a nice graphical representation of the resulting history.
At this point you could delete the experimental branch with
$ git branch -d experimental
19.This command ensures that the changes in the experimental branch are already in the current branch.
If you develop on a branch crazy-idea, then regret it, you can always delete the branch with
$ git branch -D crazy-idea
Branches are cheap and easy, so this is a good way to try something out.
20.Any Git command that needs to know a commit can take any of these names. For example:
$ git diff v2.5 HEAD # compare the current HEAD to v2.5
$ git branch stable v2.5 # start a new branch named "stable" based
# at v2.5
$ git reset --hard HEAD^ # reset your current branch and working
# directory to its state at HEAD^