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 6, 2018 in Git & GitHub by Tyrion anex
• 8,380 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 6, 2018 by Sophie may
• 9,940 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 in Git & GitHub by MD
• 41,020 points
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,850 points
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, 2019 in Git & GitHub by Alok
0 votes
1 answer
+13 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 26, 2018 in DevOps & Agile by DragonLord999
• 8,420 points
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,940 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
• 55,340 points