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

How can I combine these two steps into one?

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

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>touch foo.sh
C:\Temp\TestRepo>git add foo.sh
C:\Temp\TestRepo>git ls-files --stage
100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0       foo.sh

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 foo.sh
C:\Temp\TestRepo>git ls-files --stage
100755 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0       foo.sh

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 foo.sh

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

answered Aug 7, 2018 by Sophie may
• 10,620 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,460 points
13,508 views
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,460 points
844 views
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,460 points
3,663 views
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,260 points
857 views
+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
4,062 views
+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,620 points
14,211 views
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
1,622 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP