Some Basic Git Commands

  • git init: initializes a brand new Git repository

  • git add: stages a change.

  • git commit : saves the snapshot to the project history and completes the change-tracking process. Anything that's been staged with git add will become a part of the snapshot with git commit.

  • git status shows the status of changes as untracked, modified, or staged.

  • git branch: shows the branches being worked on locally.

  • git push: updates the remote repository with any commits made locally to a branch.

For more details: About Git


What you'll need


Suppose you have a folder called test with a README.md file, and you want to push the content in this folder to a github repository.

Here's how you do it:

%%sh
### Step 1: Initialize a Git repository in your local folder
##########

# go to the 'test' folder
cd test 
# initializes a Git repository in the test folder
git init 






## Step 2: Set your account identity in this repository.
##########
git config user.email "intodeeplearning@gmail.com"
git config user.name "intodeeplearning"






## Step 3: Make the first commit
##########
# git isn't aware of the file READ.md , stage it
git add README.md

# commit the staged changes with a message
git commit -m "first commit"

# If you'd like, rename the default branch to 'main'
git branch -M main






## Step 4: Push your local git repository to github
##########

# provide the path for the repository you created on github with Personal Access Token
# by adding remote origin
git remote add origin https://ghp_9jvw82CCplyvDBTTTqMtmZ4wLDjuqj3LufGl@github.com/intodeeplearning/test.git

# Pushes the 'main'branch in your local repository
# up to the remote repository you specified as the origin
git push -u origin main
Initialized empty Git repository in /content/test/.git/
[master (root-commit) c31e407] first commit
 1 file changed, 1 insertion(+)
 create mode 100644 README.md
Branch 'main' set up to track remote branch 'main' from 'origin'.
To https://github.com/intodeeplearning/test.git
 * [new branch]      main -> main