Unable to setup branch in git setup from scratch task

Hi @Inderpreet, @Tej-Singh-Rana, @Chudo , @Ayman ,
I am trying to understand how can i create a xfusioncorp_media and commit the changes followed by creating a master branch only after since i am getting error when doing that
Steps done:

  1. install git and set global config values [success]
  2. Create a bare repository /opt/media.git . [success]
    ** git init --bare --shared=group media.git**
  3. Clone /opt/media.git to /usr/src/kodekloudrepos . [success]
    git clone /opt/media.git /usr/src/kodekloudrepos
  4. Copy the update file from /tmp to hooks/ in .git/ dir inside /kodekloudrepos dir [success]
  5. Create a new branch xfusioncorp_media. /kodekloudrepos dir
    1st attempt : git branch xfusioncorp_media. [ failed ] [fatal: Not a valid object name: ‘master’.]
    2nd attempt: git checkout --orphan xfusioncorp_media. [ not sure if this is correct , but without master branch seems to be one way ]
  6. Copy /tmp/readme.md to /kodekloudrepos dir and commit changes .
  7. After adding and commiting readme.md , tried
git push origin

which threw an error like unable to push to url=/opt/media.git since that is the bare repo from which it was cloned . Should i create xfusioncorp_media as an orphan ?

What you are getting after running this command: – “git remote -v”


After adding and commiting readme.md , tried git push origin

You have to specify the branch name. Try the below command. It worked for me.

git push origin xfusioncorp_media

Thanks @Lakshmi , but how did you create the xfusioncorp_media , ie, did you run

git branch xfusioncorp_media

or some other command , since when i run the above command i get the error

fatal: Not a valid object name: ‘master’

since master branch does not actually exist at that point


I tried this way

git checkout -b xfusioncorp_media

Thanks will try that than .

Sure. Let me know if you are stuck.

Thank you @Lakshmi ,will try and get back to you

output was :
[email protected] kodekloudrepos]# git remote -v
origin /opt/media.git (fetch)
origin /opt/media.git (push)

Hi @Lakshmi ,
Currently the update hook fails to prevent push to master . Possibly the way i have set it up is incorrect
Initially when i cloned the bare repo to kodekloudrepos after copying update hook file to /opt/media.git/hooks/ dir , it did not clone/copy the update file to /usr/src/kodekloudrepos/.git/hooks/ dir . So i had to manually copy the file to /usr/src/kodekloudrepos/.git/hooks/ dir . Is that the way to setup the hook ?
Below is the current output showing that it is possible to push to master

[[email protected] hooks]# cat update
if [ "$1" == refs/heads/master ];
  echo "Manual pushing to this repo's master branch is restricted"
  exit 1
fi[[email protected] hooks]# cd ../..
[[email protected] kodekloudrepos]# echo 'ehllo' > test2.txt
[[email protected] kodekloudrepos]# git add .  ; git commit  -m 'another commit'
[master d742eb2] another commit
 1 file changed, 1 insertion(+)
 create mode 100644 test2.txt
[[email protected] kodekloudrepos]# git branch
* master
[[email protected] kodekloudrepos]# git push origin master
Counting objects: 4, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 295 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To /opt/news.git
   8246136..d742eb2  master -> master

looks like in the screenshot, you switched to master branch

Yes. I also did the same.

You have to create master branch from xfusioncorp_news branch.

git branch master

I ran git checkout -b master , not sure if that caused the hook to not work .

Yeah, if you run git checkout -b master, it not only creates branch master but also will be switched to master branch.