Welcome, it’s great to have you here.
In this tutorial, we learn about how to Get and Create Projects by using init and clone commands.
How to create a project by Git init?
Git init creates an empty Git repository in the project folder. .git directory with subdirectories for objects, refs/heads, refs/tags, and template files.
Follow the below steps and get it done.
Step 1:
- Check the git version on your system by using this command:
- git –version
- If it is not installed in your system so follow these steps
Step 2:
- Now hit this command for git initialization:
- git init
- After hitting this command successfully initialize git empty repository ( .git ) on your project folder.
Step 3:
- Check git status by this command:
- git status
- Here you can see, not any files are created yet.
Step 4:
- Need to create one new file for the initial commit. here I created one file README.md
- Now you can check the git status so created file show as untracked files and this will appear in red color.
Step 5:
- Need to add an untracked file in the git staging area by using this command:
- git add README.md
- Check git status after adding a file in the git staging area so this file appears in green color.
Step 6:
- Before pushing a file on the git repository, you need to commit by this command :
- git commit -m “ Commit message write here ”
Step 7:
- Now you need to push a commit to your remote directory by using this command:
- git push
- After hitting the push command you can see this error message because you need to first configure the remote repository on your local system. so let’s configure the first remote repository.
Step 8:
- You can create a remote repository by using either GitHub or GitLab
- In my case I use GitHub. Create your account and make a repository like this.
- Here I created a git remote repository as public. You can click on git remote repository so you see this. Now click on HTTPS and copy this URL. This is your remote repository URL.
Step 9:
- Now you can add a remote repository URL to your local repository by using this command :
- git remote add origin REMOTE URL
- In my case, I add a remote repository by the below command
- git remote add origin https://github.com/victorzilla/git.git
- Now you can check remote URL is configured or not by this command: git remote show origin
- You can see where your remote repository is added to your local repository.
Step 10:
- Now check your branch by this command:
- git branch
- If you do not see any branch so you can create a branch first by using this command :
- git branch -M master
Step 11:
- Now you need to push a commit to the git remote repository by this command.
- git push -u origin master
How to get a project by Git clone?
GIT clone command can clone a repository into a newly created directory.
Git clone remote URL
git clone https://github.com/victorzilla/git.git
Now you can check your remote repository is cloned into your local directory.