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 6, 2018 in Git & GitHub by Tyrion anex
• 8,280 points
100 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 6, 2018 by Sophie may
• 9,370 points

Related Questions In Git & GitHub

0 votes
1 answer

How to do a re-merge into another branch in git

Seems like you want to rebase your ...READ MORE

answered May 7, 2018 in Git & GitHub by DareDev
• 6,810 points
90 views
0 votes
1 answer

How to add a remote git repository in Jenkins

Follow these steps: Step 1 Go to Manage ...READ MORE

answered May 23 in Git & GitHub by Alok
29 views
0 votes
1 answer
0 votes
1 answer

How to solve the ‘Git commit -a error’?

This happens when no editor is set. ...READ MORE

answered Jul 5, 2018 in Git & GitHub by Tyrion anex
• 8,280 points
34 views
+13 votes
2 answers
0 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
• 9,370 points
26 views
0 votes
1 answer

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

The ‘git log’ command is your closest ...READ MORE

answered Jul 4, 2018 in Git & GitHub by Sophie may
• 9,370 points
46 views