M BUZZ CRAZE NEWS
// news

Git commit and push via batch file on Ubuntu

By Emma Martinez

Our team have to always submit code on git after their work. And on every PC there are a lot of projects. All system running with Ubuntu OS. So I need some solution for overcome this manually commit on Git.

It is good if we can submit them on a single click only (upload in batch mode folders of a PC).

2 Answers

You can do this with a bash script, example:

#!/bin/bash
### project 1 ###
cd /project1path/
git add all
git commit -m "Automatic save commit initiated at $(date)"
git push origin master --repo
### project 2 ###
cd /project2path/
git add all
git commit -m "Automatic save commit initiated at $(date)"
git push origin master --repo
...

Then you can chmod this bash script with 755 permissions like this:

chmod 755 autosave-script

After that change to UI and open nautilus and create a link on the desktop and youre done.

If the script wont start at a double click in nautilus open the file properties and change it according to the following screenshot:

enter image description here

You will have to do this step on each machine you want to use that script.

7

Thanks Videonauth for the answers, for my working of this manner:

Put in a terminal:

git config --global user.pass your-password

Where you need to change "your-password" for the password of your GitHub account.

Next put:

git config --global credential.helper store

This create the hidden file:

.git-credentials

and add new values in:

.gitconfig

This is possible see setting your file manager to see hidden files. In Dolphin this is with "Alt + .". In Nautilus, Thunar, Caja is with "Ctrl + H":

see the hidden files

Note: If you want to see the content you can open with right clic and open with Gedit

Next make the script to commit and push via batch file. Open Gedit and paste:

#!/bin/bash
### project 1 ###
cd /all/the/path/where/is/you/git/repository
git add .
git commit -m "Automatic save commit initiated at $(date)"
git push origin master
### project 2 ###
cd /all/the/path/where/is/your/other/git/repository
git add .
git commit -m "Automatic save commit initiated at $(date)"
git push origin master 

remember you must change the path for all the path where your repositories are, see this example:

to understand where is the path to the repositorie

Note: You can do this with all repositories that you want. In this example is for two repositories, but you can do it for four or five, only copy and paste and change the values.

save in your HOME with this name:

autosave-script

then put in the terminal:

chmod 755 autosave-script

next if you want to see what all happen, put in terminal:

./autosave-script

See this picture to help understand:

image to understand

this show all happen:

to see in terminal what happen

but is not necessary, just double click to make it work:

just doble clic

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy