Skip to content

Latest commit

 

History

History
346 lines (274 loc) · 9.59 KB

basic_commands.md

File metadata and controls

346 lines (274 loc) · 9.59 KB

Basic commands

Open Terminal(Mac) or command prompt(Windows) and change directory to your project working directory.Then enter these commands :-


Git Command Description Recommendation Note
git config –global user.name "[name]" 
git config –global user.email "[email address]" 
This command sets the author name and email address respectively to be used with your commits. Highly Recommended This config is only needed for first time user.
 git init  
This Command will initialize the local Git Repository for your project. Highly Recommended This is the first command needed for every project.
 git clone [enter_git_repo_url_here]
This command is used to obtain a repository from an existing URL. Recommended This is used when we want a copy/clone of a project/repository on our machine
 git add [file_name]
This Command will add a file to index or staging area. Not Recommended This is used when we want a single file to be indexed
 git add .
This Command will add the entire directory recursively, including files whose names begin with a dot. Not Recommended This command stages all files including .files which we may or may not want to stage.
 git add *
This Command will add all files in the current directory, except for files whose name begin with a dot. Highly Recommended This command stages all files excluding .files at one go
 git commit -m “[brief_message_about_this_commit]” 
This Command will commit the staged files.This command also takes a short/brief message about that particular commit Highly Recommended Meaningful commit message is recommended as it helps other developers/contributors/visitors to understand about that commit.
 git commit -a  
This command commits any files you’ve added with the git add command and also commits any files you’ve changed since then. Not Recommended This opens Shell, which might get overwhelming if you try to understand it now. To close Shell, enter Escape button on keyboard and then type ":q" then Enter.
 git status 
This Command will show you the status of the current working tree. Highly Recommended This command will help you at every stage. Alway check status before pushing the repository to the GitHub
 git diff 
This command shows the file differences which are not yet staged. Highly Recommended This command will help you identifying the difference by coloring the staged/not-staged lines with red and green and also with plus/minus symbols. When you are done, you can press the "q" or ":q" key to quit.
git diff –staged  
This command shows the differences between the files in the staging area and the latest version present. Recommended This command will help you identifying the difference by color red and green and also with plus/minus symbols. When you are done, you can press the "q" or ":q" key to quit.
git diff [first_branch_name] [second_branch_name]  
This command shows the differences between the two branches mentioned. Recommended This command will help you identifying the difference by color red and green and also with plus/minus symbols. When you are done, you can press the "q" or ":q" key to quit.
git reset [file_name] 
This command unstages the file, but it preserves the file contents. Recommended This command will remove the particular file from stage area.
git reset [commit_id] 
This command undoes all the commits after the specified commit and preserves the changes locally. Recommended Use this command if you know what you are doing. check status of the changes to keep track.
git reset –hard [commit_id]
This command discards all history and goes back to the specified commit. Recommended Use this command if you know what you are doing. check status of the changes to keep track.
git rm [file_name]
This command deletes the file from your working directory and stages the deletion. Recommended Use this command if you know what you are doing.Check twice which file you are about to delete. Check status of the changes to keep track.
git log
This command is used to list the version history for the current branch Highly Recommended Also Check status of the changes to keep track.
git log –follow[file_name]
This command lists version history for a file, including the renaming of files also. Highly Recommended Also Check status of the changes to keep track.
git show [commit_id]
This command shows the metadata and content changes of the specified commit. Highly Recommended Also Check status of the changes to keep track.
git tag [commit_id]
This command is used to give tags to the specified commit. Recommended A lightweight tag is very much like a branch that doesn't change — it's just a pointer to a specific commit.
git branch
This command lists all the local branches in the current repository. Highly Recommended useful when working in a team
git branch [new_branch_name]
This command creates a new branch. Highly Recommended Alway create a branch if you are not sure about feature you are about to add.
git branch -d [branch_name] 
This command deletes the particular branch. Highly Recommended Delete branch when you have merge the feature with the master branch
git checkout [branch_name]   
This command is used to switch from one branch to another. Highly Recommended Branching the project feature and the merging it, is very helpful.
git checkout -b [branch_name]    
This command creates a new branch and also switches to it. Highly Recommended Branching the project feature and the merging it, is very helpful.
git merge [branch_name]      
This command merges the specified branch’s history into the current branch. Highly Recommended Branching the project feature and the merging it, is very helpful.
git remote add [variable_name] [Remote_Server_Link]   
This command is used to connect your local repository to the remote server. Highly Recommended Default Remote is "origin" but you can change as per your preference
git push [variable name] master  
This command sends the committed changes of master branch to your remote repository. Highly Recommended Default Remote is "origin" and default master branch_name is "master" but you can change as per your preference
git push [variable name] [branch]    
This command sends the branch commits to your remote repository. Highly Recommended Default Remote is "origin" and default master branch_name is "master" but you can change as per your preference
git push –all [variable name]    
This command pushes all branches to your remote repository. Highly Recommended Pushes all new updates to the server's repo.
git push [variable name] :[branch name]  
This command deletes a branch on your remote repository. Recommended Use this command if you know what you are doing.Check twice which file you are about to delete. Check status of the changes to keep track.
git pull [Repository_Link]  
This command fetches and merges changes on the remote server to your working directory. Recommended Basically updates and merges the changes on your local repo


Don't be frustrated with all this commands.
The best way to learn, is to make lots of mistakes.