Level 1 : Very basic one for git
Basic commands | What does it do |
mkdir | Make new directory |
cd | open current directory |
cd .. | go back |
ls | lists out all the files which are in working directory |
ls -a | lists out all the files along with hidden files in working directory |
git ls-files | lists out all the files which are in staged area |
cat > file_name.extension | creates a new file and lets you add content in it ( it is followed by Ctrl + Z to stop taking input) |
mv source-files destination-directory | moves specified files which are in current directory to the destination directory |
Vim
Just like nano and notepad, we have a text editor vim. On Window, vim is a default text editor in git bash. Let's get started with vim
Before making our first commit, we run:
vim
in the terminal.
It starts in "normal mode". It has very few commands to remember and they are as follows :
Command (Press these keys) | Description |
i | To insert/ type |
Esc | To exit the editing mode and get back to "normal mode" |
:w | To save our work |
:q | To exit vim |
:x | To save and exit at a same time |
Level 2 : Frequently used between current workspace, staging area, local repository
Git Commands | What does it do |
git init | Adds version control to a particular working directory |
git add | Sending files from working directory to staging area |
git commit | Sending files from staging area to local repository |
git status | To get the status of all the files |
git status -s | To get precise status of files |
git push | Moving files from local repository to remote repository |
git clone | Create a new local repository from the remote repository |
git pull | To get updated file from remote repository to local repository |
Extras in the above commands :
git add
Git commands with example files | Description |
git add . | Adds all the files in working directory |
git add *.txt | Adds all txt file |
git add a.txt b.txt | Adds specific files |
git commit
Git commands with example files (a.txt, b.txt) | Description |
git commit a.txt b.txt | Commits the a.txt amd b.txt files. Commit by default is going to consider the files from staging areas. So you don't have to specify the file names. |
git commit -m "This is a commit message" | While committing it's mandatory to give commit message |
git commit -a -m "This is a commit msg" | If you want to add and commit a modified file then you can do both by using this command |
git config
Git commands with example files | Description |
git config user.name "" git config user.email "" | This command will set user-name and email of current directory only |
git config --global user.name git config --global user.email | All the commit changes made to a file in local repository will be stored under this user.name and user.email at global level i.e. this user name and email will be used for all commit changes for all repository |
git config --list | To list out all git configurations - Will display configuration details which are at global level - We specially use this to find user name and email |
git log
Some specific commands of git log | What does it do |
git log | Display's history of all the commits of our local repository |
git log --oneline | Display one line commit of all the file history (This option is very helpful when we have a lot of commits and to identify commits based on message) |
git log --help | to get specified information |
git log file.txt | to see log info about a particular file |
git log -n 2 / git log -2 | -n option limits the number of commits to display. Here I have specified 2 so the latest two commits will be displayed over here. |
git log -n 2 --oneline | display;s one line commit and last 2 commit |
git log max-limit ="2" | This also does the same thing as git log -n 2 |
git log --grep="Pattern" | grep is used to search based on a given pattern in the commit message. Here the Pattern are those words which are in commit message |
git log --decorate | To display meta information like branch name, HEAD, tag's information |
To display commits from specific time/date :
--since="YYYY-MM-DD"
--after="YYYY-MM-DD"
--after="3 hours ago"
Here after and since are same
To display all the commits till a specific time/date:
--until
--before
git log --before="4 days ago" will display all the commits till 2 days ago.
To display commits based on author:
--author =<pattern>
git log --author="Gautami" will display all the commits made by gautami