简体   繁体   中英

Unable to push to forked repo using git commit and push using a script

I have forked a repository on GitHub and clone the forked repository to my local with following .git/config :

[core]
        repositoryformatversion = 0
        filemode = true
        bare = false
        logallrefupdates = true
        ignorecase = true
        precomposeunicode = true
[remote "origin"]
        url = git@github.com:namannigam/commons-io.git
        fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
        remote = origin
        merge = refs/heads/master
[remote "upstream"]
        url = git@github.com:apache/commons-io.git
        fetch = +refs/heads/*:refs/remotes/upstream/*

Now that I have a script formulated(indented for question readability) for such repositories to be in sync with the upstream and pushing my latest code to the server (my forked branch) with something like this :

cd $d # traverse directory
&& git checkout master # checkout the master branch of my fork
&& git fetch -a # fetch all the branches
&& git fetch upstream # https://help.github.com/articles/syncing-a-fork/ 
&& git pull upstream master
&& git merge upstream/master
&& git commit -am "`date`" #commit the current code 
&& git push origin master #push the code to the master of my fork

The challenge that I am facing is that the push to my origin/master doesn't succeed with the above script. On the other hand, if I execute all the commands sequentially on the command prompt it works.


What I noticed was that the combination of commit and push is making it difficult for me to execute the script since the behavior is same as when executing the following separately on the command line from project directory :

git commit -am "`date`" && git push origin master  #results into no push

If in case it may matter:

git --version => 2.16.1

On-demand sample logs against the above script commands for one of the projects :

 Already on 'master' Your branch is up to date with 'origin/master'. remote: Counting objects: 350, done. remote: Compressing objects: 100% (120/120), done. ... From github.com:dropwizard/dropwizard 4db822962..3f9cf2253 master -> upstream/master * [new tag] v1.3.0-rc5 -> v1.3.0-rc5 From github.com:dropwizard/dropwizard * branch master -> FETCH_HEAD Updating 4db822962..3f9cf2253 Fast-forward docs/pom.xml | 2 +- .... # list of files wiht lines changed ++++++++++----------- 49 files changed, 147 insertions(+), 116 deletions(-) Already up to date. On branch master Your branch is ahead of 'origin/master' by 21 commits. (use "git push" to publish your local commits) nothing to commit, working tree clean 

git commit returns 1 if nothing was committed and subsequent chain after && operator is not executed (because it requires success aka 0 ).

Try ; instead of && when joining last git push

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM