Skip to main content

Command Palette

Search for a command to run...

Gtit & Github For Automation Tester

Updated
•3 min read•View as Markdown

Add one Folder to VS-code workspace ad Git-Learning ,& added more folder as one, two, three, four.

And open the Git-Learning Folder**/**Project in Terminal Then Run command as “git status”.

As it is not initial as git folder, it will show this message

fatal: not a git repository (or any of the parent directories): .git

Then by entering cd one as we want to initialize git inside one folder.

Then the result is

It also gives a hint at some of git commands.

And git file is created inside one folder , but it will not show in VS Code. you need to change the setting in VS Code.

Through CLI also we can see the list of folder/file available in side a folder ,by command ls

still it not showing anythings.

But by using ls -la we can see th hideen folders and files.

it shows the all the hidden files.

But we can see the by change the setting in VS code that is the beauty of VS code.

Git Branching

here is some common git branch commands.

Action

Command

Description

List Branches

git branch

Shows all your local branches.

List All Branches

git branch -a

Shows all local and remote-tracking branches.

Create Branch

git branch <branch-name>

Creates a new branch, but does not switch to it.

Switch to Branch

git switch <branch-name>

Switches your working directory to an existing branch.

Create & Switch

git switch -c <branch-name>

Creates a new branch and immediately switches to it.

Rename Branch

git branch -m <new-name>

Renames the current local branch.

Safe Delete Branch

git branch -d <branch-name>

Deletes a local branch only if it has been merged.

Force Delete Branch

git branch -D <branch-name>

Deletes a local branch regardless of its merge status.

Push New Branch

git push -u origin <branch-name>

Pushes a new local branch to the remote (origin).

Delete Remote Branch

git push origin --delete <branch-name>

Deletes a branch from the remote repository.

Lets Create another Branch by using command git branch <branch-name>

O O whats happen ?

it show as fatal: not a valid object name: 'master' ,but why?

happens because Git can’t find a branch (or commit) named master to base your new branch on.

🔍 Possible Reasons

  1. Your repo has no commits yet.

    • You can’t create a new branch until at least one commit exists.

    • If you only ran git init and haven’t committed anything, Git doesn’t know what main is.

  2. Default branch isn’t really main.

    • In older Git versions, the default branch is master, not main.

    • If your repo uses master, Git won’t recognize main.


✅ Fix Steps

  1. Check current branches

     git branch
    

    This shows the existing branches. If you see only master, then your default branch is master, not main.

  2. Make an initial commit (if none yet)
    If your repo is completely empty:

     git add .
     git commit -m "Initial commit"
    

But it show now as below

That mean we must should have one file to track the repositoty ,and then after we can create branch.

Aftrer adding one file to repository.

Now you’ll have a base commit.

  1. Create a branch from current branch
    If you’re already on main (or master), just do:

     git checkout -b bug
    

    or

     git branch bug
    

👉 Quick check for you:
Run this and tell me what you see:

git branch

That will confirm whether your repo has main, master, or no commits yet.

More from this blog

Shreenibas Samal's blog

49 posts