This document is for those people who are relatively new to GitHub but know the basic concepts like repositories and commits etc. For experts this document can act as a revision document.
Happy learning!!
-
Creating a repository:
git init
You need to be in the repository that is to be initialised as the git repository -
Checking status:
git status
Command gives the current status of the the repository irrestective of file being commited or not. Status includes whether file is 'tracked' or 'untracked' or 'modified' etc. -
Adding file:
git add <file_to_add>
Adds the specified file to staging area
git add .
Adds all untracked files to staging area
git add *.<extension>
Adds all files with the specified extension
Adding is only done to the staging area and not to the final commit straight away!! -
Making a commit:
git commit
Command redirects to an editor where you have to specify some description regarding the commit. This commits the files that were present in the staging area only!! -
Unstaging a file:
git rm --commit<file_name>
Removes the file from the staging area and transfers it back to the modification area. -
Changed files:
git diff
Command shows the changes made to the files. Command works only when the file is in the unstaged area.
For staged files:git diff --staged
-
Pushing to remote repo:
git remote add origin <url to the remote repo>
git push -u origin <branch to which pushin is to be done>
-
Pulling from your own remote repo to a locally existing repo
git pull <url of remote repo> <branch>
To pull into a local repo the command prompt control needs to be inside the repo