Useful Commands in Git


The following commands are commonly used in Git.

1. To clone a local repository from a Git server
# git clone git@'server-addr':'repository'

2. To check the status of a local repository
# cd 'repository'
# git status

3. To check the difference between a local repository and one in Git
# cd 'repository'
# git diff

4. To synchronize a local repository with one in Git
# cd 'repository'
# git pull

5. To add file to a local repository
# cd 'repository'
# git add 'file'

6. To move files in a local repository
# cd 'repository'
# git mv 'file' 'new-file'

7. To remove some file in a local repository
# cd 'repository'
# git rm -n 'file'
# git rm -f 'file'

8. To remove all newly added (uncommitted) files in a local repository
# cd 'repository'
# git clean -n
# git clean -f

9. To commit all modifications of a local repository
# cd 'repository'
# git commit -a -v -m 'commit-msg'

10. To undo the last commit of a local repository
# cd 'repository'
# git revert HEAD

Free Web Hosting