first things firstlet git know your name and email:git config --global user.name "Your Name"git config --global user.email "email@example.com"
git initCreate an empty git repository or reinitialize an existing one$ mkdir getonwithgit$ cd getonwithgit/$ git initInitialized empty Git repository in /Users/hrahman/test/getonwithgit/.git/
git add(master)$ echo "Hello World" > hello.txt(master)$ git status# On branch master# Initial commit# Untracked files:# (use "git add <file>..." to include in what will be committed)# hello.txtnothing added to commit but untracked files present (use "git add" to track)(master)$ git add hello.txt(master)$ git status# On branch master# Initial commit# Changes to be committed:# (use "git rm --cached <file>..." to unstage)# new file: hello.txt
git diffgit diff: Show differences between your working directory and theindex.git diff –cached: Show differences between the index and themost recent commit.git diff HEAD: Show the differences between your workingdirectory and the most recent commit.
git commit --amendyou commit and then realize you forgot to stage the changes in a fileyou wanted to add to this commit:$ git commit -m initial commit$ git add forgotten_file$ git commit --amend
branchcreate a new branch:(master)$ git checkout -b dev_featureSwitched to a new branch dev_featureswitch to an existing branch:(dev_feature)$ git checkout masterSwitched to branch master(dev_feature)$ echo "new feature" > feature.txt(dev_feature)$ git add feature.txt(dev_feature)$ git commit -m "feature"
branchdelete a branch$git branch -d dev_new_branchshow all local branches:$git branchshow all local and remote branches:$git branch -a