Git and GitHub for Beginners Part3

Here comes part 3, in the previous two blog posts we had discussed git installation, how to create a repository, and many more. If you haven’t read the basic theory part then I strongly recommended you to read the first two-part and then start practicing.

Click here for GitHub for beginners Part1 and GitHub for beginners Part2

Imagine that you have a project and you want to work with GIT. So let’s follow the steps shown in the image below. Open the GIT BASH.

Master:- It is a single and main branch. It is thereafter repository creation.

.init: – Then we specify the init the “.git” folder gets generated.

git add: – we have already learned the previous two posts.

git add .

git status: – To check the status of your file.

git status

How to add specific extension file?

git add *.java
$ git commit -m "first commit"

-m: – Is used to give the comment information.

Open your file in a text editor. Do some changes and again check the status.

git status -s
 M test.txt

In the above code, M stands for something that is changed in our file.

 git commit -a -m "new changes"

How to create “.gitignore” file?

touch .gitignore

Specify the file extension which you want to ignore.

How do I ignore a specific file in Git?

git rm --cached FILENAME

–cached: – Means to keep the file in the working directory, but interested to remove it from staging.

How do I remove a directory from a staging area in git?

git rm -r --cached bin/

If we want to remove all the files from the specific directory use the “-r: – recursive”. The internal directory will also be removed from the staging.

You can specify the bin folder in your “.gitignore” file as well.

How to update last commit message using GIT?

git log -1

Using, above flag, will show you the last commit message.

git commit --amend

Amend: – Takes current staging area and uses it for the commit.

So we have added or updated the last commit message again write the code.

How to update changes but not the commit message?

  1. Open your code file, do the changes which you want to, for example, you forgot to specify the “;” or anything.
  2. Ctrl + S
  3. git add .
git commit --amend --no-edit
git log -1

How to push data?

See you in next GIT POST… Click Here

Till then interested to read regarding ANGULAR CLICK HERE

Leave a Comment