Git and Github Tutorial
Open a Github Account from Github.
Install git in Linux
$ sudo yum install git
When you install Git is to set user name and email address.
$ git config —global user.name “John”
$ git config -global user.email john@example.com
$ git config -—list
$ git config user.name
Get Github help
$ git help config
Initializing a repository in an existing directory
$ git init
$ git init Algorithm
Start version-controlling existing files
Get a copy of an existing Git repository
$ git clone https://github.com/libgit2/libgit2
Check git status
$ git status
Trace files
$ git add README.md
$ git add *
$ git add *.c
$ git status
$ git status -s
You’ll have a class of files that you don’t want Git to automatically add or even show you as being untracked. And u can get github ignore list : https://github.com/github/gitignore
$ cat .gitignore
See what you’ve changed but not yet staged
$ git diff
$ git diff —cached
Commit changes and push
$ git commit -m “first commit”
$ git commit -a //jump git add
$ git push
$ git push --set-upstream origin master
$ git push -u origin master
Remove files
$ rm README.md
$ git rm README.md
$ git rm log/\*.log
Change file name
$ git mv file_from to file_to
$ git mv
Check history
$ git log
Shows the difference introduced in each commit
$ git log -p -2
$ git log —-stat
Shows you where the branch pointers are pointing
$ git log --decorate
Display an ASCII graph of the branch and merge history beside the log output.
$ git log —-graph
$ git log --decorate --graph
Undo things
$ git commit -m “first commit”
$ git add forgotten_file
$ git commit —-amend
Upstaging a staged file
$ git add *
Then u want to to unstage README.md file
$ git reset README.md
$ git checkout —- README.md
Remote
$ git remote
$ git remote show origin
$ git remote iv
$ git remote add origin https://github.com/Shanshan-IC/Algorithm.git
$ git remote rename pb paul
$ git remote rm paul
Fetch all the information that Paul has but that you don’t yet have in your repository,
$ git fetch pb
Get data from remote projects
$ git fetch origin
Tag
$ git tag
$ git tag v.1.0
$ git show v.1.0
Share tag
$ git push origin v.1.0
$ git checkout -b new branch v.1.0
Branch
Get new branch
$ git branch testing
Switch branch
$ git checkout testing
Get a new branch and switch to it
$ git checkout -b testing2
Merge branch
$ get checkout master
$ get merge testing2
After merge, delete branch
$ git branch -d testing2
But if there are conflicts between merge, have to solve it manually
$ git mergetool
$ git commit
Check branch things
$ git branch -v
$ git branch —-merge
If you want to learn something more, please visit the website: https://git-scm.com/book/en/v2