Let's explore each command in detail.
Create new directory for Git initiation
- Create a directory with "first_git_repo" and navigate into it using "cdfirst_git_repo" for Git initiation.
Initialize a new Git repository
Create two files, add them to staging :
Use VIM command to create two file file1.txt , file2.txt
Use the git add command to add the newly created files to the staging area, preparing them for the next commit.
Command used to add all files: git add .
You can check file status using git status command .
Commit the changes :
Execute the git commit command to permanently save the changes made to the files along with a descriptive commit message.
syntax: git commit -m "commit message"
-m flag allows you to include a commit message directly in the command. This message should describe the changes made in this commit.
To check changes between working file and last commit
git diff shows changes between the working directory and the last commit
To remove file from staging
To set username and user email
git config --global user.name "ankitgithub25" sets the global Git username
git config --global user.email "ankitkondal91@gmail.com" sets the associated email address.
To clone a remote Git repository to a local machine
Local: On your machine.
Remote: Hosted on platforms like GitHub .
In Github, manually create new repository "git_demo_repo"
Then, create new file "demo.txt" under it using "Create new file" option.
In terminal, create new directory "git_repo_remote" for cloning our remote repository "git_demo_repo"
Navigate to git_repo-remote using cd
Clone the remote repository using the git clone command. Replace <repository_url> with the URL of the remote Git repository:
syntax: git clone <repository_url>
You can find this url in github under code tab
-
Now, you have successfully cloned a remote Git repository to your local machine.
git push: Uploads local changes to a remote repository.
git pull: Fetches changes from a remote repository and merges them into the local branch.
Thanks & Happy learning !!