How to give a file execute mode permissions in Git

0 votes

My git is installed on a Windows OS and I want to push an executable shell script into the git repo. I can perform this in two steps, is there a way I can do this is one step?

I need to do make two git commits:

$ vi
$ git add  
$ git commit -am "add new file for installation" # commit1
[master f2e92da] add support for
 1 files changed, 18 insertions(+), 3 deletions(-)
 create mode 100644
$ git update-index --chmod=+x
$ git commit -am "update file permission"        # commit2
[master 317ba0c] update file permission
  0 files changed
  mode change 100644 => 100755

How can I combine these two steps into one?

Aug 7, 2018 in Git & GitHub by Tyrion anex
• 8,700 points

1 answer to this question.

0 votes

You can easily do this in one commit, you can add the file and mark it executable. Just follow the below steps:

C:\Temp\TestRepo>git add
C:\Temp\TestRepo>git ls-files --stage
100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0

Note that, after adding, the mode is 0644 (ie, not executable). Now, we can give it executable permissions before committing:

C:\Temp\TestRepo>git update-index --chmod=+x
C:\Temp\TestRepo>git ls-files --stage
100755 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0

Now the file is mode 0755 , which is the executable mode

C:\Temp\TestRepo>git commit -m"Executable!"
[master (root-commit) 1f7a57a] Executable!
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100755

Now we have a single commit with a single executable file.

answered Aug 7, 2018 by Sophie may
• 10,610 points

Related Questions In Git & GitHub

0 votes
1 answer

How to untrack a file in Git?

Hi@akhtar, You can untrack your file from git ...READ MORE

answered May 4, 2020 in Git & GitHub by MD
• 95,440 points
0 votes
1 answer

How to unstage a file in Git?

Hi@akhtar, Sometimes we accidentally add files in the ...READ MORE

answered Nov 19, 2020 in Git & GitHub by MD
• 95,440 points
0 votes
1 answer

How to force git to completely forget about a file that is present in .gitignore folder?

Hi@akhtar, gitignore file is a text file that tells Git which files or ...READ MORE

answered Dec 22, 2020 in Git & GitHub by MD
• 95,440 points
0 votes
0 answers

How to find and restore a deleted file in a Git repository?

Hi Team, I have one Git repository. I ...READ MORE

Dec 22, 2020 in Git & GitHub by akhtar
• 38,230 points
+15 votes
2 answers

Git management technique when there are multiple customers and need multiple customization?

Consider this - In 'extended' Git-Flow, (Git-Multi-Flow, ...READ MORE

answered Mar 27, 2018 in DevOps & Agile by DragonLord999
• 8,450 points
+2 votes
1 answer
0 votes
1 answer

How to forcefully commit a file to Git even if the file is ruled as unchanged?

This is simple, just follow the below ...READ MORE

answered Jul 11, 2018 in Git & GitHub by Sophie may
• 10,610 points
0 votes
2 answers

How to view the nested workflow of a local git repository?

The closest way to view branches in ...READ MORE

answered Aug 2, 2019 in Git & GitHub by Sirajul
• 59,230 points
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP