The following are some commands that will get you started on using GIT. See also:
Quick guide to GNUPlot
Quick guide to Docker
Quick guide to CVS
Quick guide to nawk
Quick guide to Emacs
Quick guide to GNUPlot
Quick guide to NSCC ASPIRE2A
To create a new GIT Repository with files in the current directory and sub-directories (the current directory can be empty).
> git init
Some basic configurations:
> git config --global name = "[your name]"
> git config --global email = "[your email]"
> git config --global core.editor "emacs"
> git config --global color.ui true
To check the status of the current GIT repository
> git status
To add a file in the current working directory to the staging tree
> git add [filename]
To commit the changes from the staging tree to the repository
> git commit -m "[add a short message on the changes here]"
To view what are the changes in the working directory
> git diff
To view the changes in the staging tree
> git diff --staged
It can be helpful to use the following option for diff to highlight the words that are different
> git diff --color-words
To navigate within the results of git div, use the following keys:
Next line : return
Next page/ Forward : f
Previous page/Backward : b
Quit viewing the diff : q
Toggle line wrap : -S
Help : h
To remove a file from the repository
> git rm [filename]
To commit all files directly to the repository and skip the staging tree, use the following command
> git commit -am "[Commit message]"
To show the last few commits
> git log
> git log --oneline
To show the changes of a specific commit
> git show [full or partial sha code] --color-words
To compare the changes between two commits
> git diff [commit1 shacode]..[commit2 shacode] --color-words
> git diff [commit1 shacode]..HEAD --color-words
To undo changes that have not been staged
> git restore [filename]
or
> git checkout -- [filename]
note that the "--" in the command tell GIT to check out from the current branch.
> git checkout -- .
This undo the changes to all files
To un-stage changes that have been staged
> git restore --staged [filename]
or
> git reset HEAD [filename]
To append changes to the most recent commit
> git commit --amend -m "[Commit message]"
To check out an old version of file in the current branch
> git checkout [shacode] -- [filename]
To revert a previous commit
> git revert [shacode]
To remove untracked files
> git clean -f
The above command will remove all untracked files
or
> git clean -n
The above command will only list the files to be removed but does not remove them.
To specify some files to be ignored by Git, create a “.gitignore” file in the directory. The content of the file can be as follows:
- regular expression: e.g. *?[aeiuo][0-9]
- sub-directories: e.g. log/*.txt
- negative expression: e.g. !index.php tells Git not to ignore index.php
- to ignore all files in a directory, ends the line with a trailing slash: e.g. review/images/
- comment: # This is a comment
Github has a good collection of .gitignore template at: https://github.com/github/gitignore
To ignore files globally in all repositories, specify a global .gitignore file as follows:
> git config --global core.excludesfile ~/.gitignore_global