krazymulataka krazymulataka - 1 month ago 17
Git Question

GIT bash commit push script

I have a git project, where we checkin in to our own branch (lets call it new_feature) and then do pull requests to merge to develop.

What I'd like my script to do is run in Bash. The script should rebase my new_feature branch from develop, we can force overwrite everything as we'd like the new_feature branch to be the exact same as develop. So perhaps we could even delete the old new_feature branch at the start of each bash script run and then create a new on? Then the script will copy some files from a different folder outside of the git repo and copy these files into my git project "new_feature" branch. Then we can commit and push the new_feature branch.

After this I will manually do the pull request to develop from our GIT web UI.

NOTE: the files I'll be copying to the local GIT repo will just be from one folder on my locale machine to a single folder within the GIT repo.

Answer

Try something like this:

#!/bin/bash
cd <repo_path>
git fetch
git branch -D new_feature
git checkout -b new_feature origin/develop
cp <some_files> <some_paths>
git commit -a
git push origin new_feature