Staging Area & Commits and Pull, Push in Github

 

Staging Area & Commits

Creating a Commit

Working Directory

We shall refer the project folder as Working Directory.

Let’s add two files

alice.txt
and
bob.txt
to our working directory.

touch alice.txt
touch bob.txt

Git’s View of Repository

Inspecting a Repository

Git tracks the changes in the working directory.

  • git status
     shows the changes in the working directory

Making Changes

Added some content to

alice.txt
and
bob.txt
files.

alice.txt:

Hi
What about your learning
Is it going good?

bob.txt:

Hi
What's your name?

Steps in Creating a Commit

  1. Add changes to the staging area.

  2. Creating a commit with changes in staging area.

Step 1: Adding Changes To Staging Area

git add
adds the changes to the staging area.

Syntax :

git add file_path

Example :

git add alice.txt

Step 2: Committing Changes

commit
is a snapshot of the project's currently staged changes.

Syntax :

git commit -m "message"

Here

message
provide useful information about what has changed and why.

Example :

git commit -m "adds alice file"

Listing all commits

git log
lists all commits.

git log

Sample output :

Here HEAD refers to the current commit.

Commit Id

Commit IDs are unique strings(hashes) that are created whenever a new commit is recorded.

8f00aaa0248bcdc38a8d8ba6267167a0478f5a63
is commit id in above Example .

Unstaged Changes

git diff
shows the unstaged changes.

git diff

Sample output :

diff --git a/alice.txt b/alice.txt
index e69de29..35dc461 100644
--- a/alice.txt
+++ b/alice.txt
@@ -0,0 +1,2 @@
+Hi
+What about your learning
+It’s going good

Uncommitted Changes

git diff --staged
shows the staged and uncommitted changes.

Working with Remote Repository

Pushing Commits

git push
command is used to publish new commits from local to a remote repository.

Syntax :

git push -u origin master
Warning

From August 12, 2021, Github has disabled authentication of

git clone
,
git push
and
git pull
commands with password. You need to create a personal access token and use it for
git
commands instead of password. The steps to create your personal access token are mentioned in this link: Creating a Personal Access Token

You can also edit file and commit changes through github Website

Editing File

  • Click on the file you want to edit.

  • Click on pencil icon to open editor :

Commit Changes

To commit changes click on Commit changes .

To share specific link of a commit, follow below steps:

  • Click on commits to view all commits.

  • Click on commit id of commit you want to share.

  • Copy the url and share.

Pull Commits

git pull
is used to pull latest commits from a remote repository to your local repository.

git pull origin master
Warning

From August 12, 2021, Github has disabled authentication of

git clone
,
git push
and
git pull
commands with password. You need to create a personal access token and use it for
git
commands instead of password. The steps to create your personal access token are mentioned in this link: Creating a Personal Access Token

Post a Comment

Please Select Embedded Mode To Show The Comment System.*

Previous Post Next Post

Contact Form