Basic Operation in Local
- Initialize a Git Repository
git init
This command will create a empty repository. There will be a .git floder which is used for tracking and managing repository.
- Adding File from Working Directory to Stage
git add [filename]
- Commit the changes in Stage to Local Repository
git commit -m "[commitment descriptions]"
- Check Current Status
git status
- Show the Differences
git diff
- Discard the Modifications in Working Directory
git checkout --[filename]
Actually, this command replace the file in working directory with the file in repository.
- Unstages the file
git reset Head [filename]
Just like delete the file in the stage, but in working directory, the file still preserves its contents.
- Remove File
git rm [filename]
- Renamce File
git mv [original filename] [new filename]
Version Control
- Lists Version History for the Current Branch
git log
- Back to Specific Commit
git reset --hard [commit id]
Branch Operation
- Lists all local branches in the current repository
git branch
- Create new branch
git branch [branch name]
- Branch Switch
git checkout [branch name]
- Merge Another Banch to Current Branch
git merge [branch name]
- Delete Branch
git branch -d [branch name]
Working with Remote Repository
- Link Local Repository with Remote Repository
git remote add origin [url]
- Build a Local Repository Copy using Remote Repository
git clone [url]
- Get Remote Repository Infomation
git remote
- Upload Local Repository Modifications
git push [remote repository name] [remote brunch name]
Default remote repository name is origin
- Download Remote Repository Modifications
git pull