Git?? A big illusion for me from beginning is coming to an end today after an year thought process(never tried or implemented) 😛
1.Git installed in your machine
I wont explain stories here..just before going to implementation lets know some basic commands..
Request to go thru this url..if not know some important concepts and commands that are listed below..
Important Git concepts
Here are the basic terms you should familiarize yourself with before embarking on your journey.
- Repository / Repo : This is the project’s source code that resides on github.com’s servers. You cannot modify the contents of this repository directly unless you were the one who created it in the first place.
- Fork : Forking a project will create a copy of the original repository that you can modify as you please. Forked projects will appear in your own github.com account.
- Cloning : this will clone an online repository to your hard drive so you may begin working on your modifications. This local copy is called your local repository.
- Branch : A branch is a different version of the same project. In the case of T2DMIT, you will see 2 branches : the master branch and the development branch.
- Remote : A remote is simply an alias pointing to an online repository. It is much easier to work with such aliases than typing in the complete URL of onlinerepositories every single time.
- Staging Area : Whenever you want to update your online repository (the one appearing in your github.com account), you first need to add your changes to yourstaging area. Modifying files locally will not automatically update your staging area‘s contents.
Important Git commands
- Fetch : git fetch will download the current state (containing updated and newly created branches) of an online repository without modifying your local repository. It places its results in .git/FETCH_HEAD.
- Merge : git merge will merge the modifications of another branch into the current working branch.
- Pull : git pull is actually a combination of git fetch and git merge. It fetches the information from an online repository‘s branch and merges it with your local copy.
- Add : Whenever you modify a file in your local repository or create a new file, that file will appear as unstaged. Calling git add allows you to specify files to be added to yourstaging area.
- Commit : A commit records a snapshot of your staging area, making it ready to bepushed to an online repository.
- Push : git push will take all of your locally committed changes and upload them to a remote repository’s branch.
Now lets config git initially..
Goto your project folder in your windows..say c:/workspace/myproeject/
Here first config git with your desired username and email like shown below
git config --global user.name "Your Name here"
This will be the name that shows up in the commits whenever you make a modification
git config --global user.email "firstname.lastname@example.org"
Make sure to enter the email address that is associated with your github account!
Now, from your command prompt(from your project folder)
c:/workspace/myproject/> git init //this will create .git in your project folder
c:/workspace/myproject/> git add –all //this will add all your files
wanna exclude a file/directory from your root folder?? then create a file and save as .gitignore extension. Once you create that just mention file name/folder name in that..
eg: node_modules folder need not commit right? then just mention node_modules in that file. Else a php file?? then
If you want to add only a folder to your repository..you can try
git add foldername
c:/workspace/myproject/> git commit -m”first commit” // your commit message
So far, the above steps is what you would do even if you were not using github. They are the normal steps to start a git repository. Remember that git is distributed (decentralized), means you don’t need to have a “central server” (or even a network connection), to use git.
Now you want to push the changes to your git repository hosted with github. To you this by telling git to add a remote location, and you do that with this command:
git remote add origin https://github.com/yourusername/your-repo-name.git
Once you have done that, git now knows about your remote repository. You can then tell it to push (which is “upload”) your commited files:
git push origin master (or) git push -f (or)
git push -f origin <branch> here branch is master
for delete a file from git repository..go to that specific folder and type ‘git rm file.ext’
With this you will be prompted for username and password in your command prompt..once you enter valid credentials..your files will be uploaded to your git account successfully. Thats it..you are done with your work and successfully uploaded all your project files to your account.
To clone from other desktop..try
git clone repository_name /path/to/localrepo/
Once clone is done..you can check files status with
and pull all files using
if you are unable to pull files..try
git reset –hard and then git pull
git clone https://github.com/angular/material-start.git(your git repository url)
cd material-start (or) cd yourproject_foldername
We have two kinds of dependencies in any project: tools and angular framework code. The tools help us manage and test the application.
We have preconfigured
npm to automatically run
bower so we can simply do:
Behind the scenes this will also call
bower install. You should find that you have two new folders in your project.
node_modules – contains the npm packages for the tools we need
bower_components (or) app/bower_components – contains the angular framework files
Note that the
bower_components folder would normally be installed in the root folder but material-start changes this location through the
With this you cloned and install all dependencies that are required to run your project. Now you have to just run
grunt serve (or) grunt serve –force
check the .gitignore file, if the subdirectory/any directory is ignored.
You can configure git to your favorite editor sublime text and work with all git commands right from sublime editor. You can check this url to configure git in sublime.
Advanced git commands:
If you get some error like changes not staged for commit git or no changes added to commit (use “git add” and/or “git commit -a”). Then try below command
git commit -am "message"
Mac command to clear git credentials and force prompt to ask username and pwd
git config --system --unset credential.helper
How to add all modified files using git?
git add -u
How to add untracked files using git?
git add -i