Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How could I commit to remote branch one by one automatically

Tags:

git

Suppose I have the following commits in my local branch,

the oldest is 17081fa, the latest is 12ba64e

How could I push these commits to remote git server one by one.

Take an example,

I don't want to push all local commits at once.

the push order should be

17081fa -> 30854d2 -> ... -> 12ba64e

These commits are ready to push to server, but need to be pushed one by one,

I need to know what's the command can let me do that way, thanks

* 12ba64e 
* 0fdf1a6 
* 75428a3 
* 00f837f 
* da9d16d 
* 3f34af9 
* b6066e9 
* cdf2dbf 
* 0d5cc8b 
* db8744c 
* df564b9 
* 30854d2 
* 17081fa 
like image 975
newBike Avatar asked Dec 10 '15 10:12

newBike


People also ask

How do I commit to a specific remote branch?

Conclusion. To push to a specific branch in Git, open Git Bash and navigate to the directory from which you want to push files to the remote branch. Then, initialize the directory using the “$ git init” command. Next, run the “$ git add .” command to add all files.

Does git push push automatically branch?

If you run the simple command git push , Git will by default choose two more parameters for you: the remote repository to push to and the branch to push. By default, Git chooses origin for the remote and your current branch as the branch to push.

Should I use git pull or fetch?

When comparing Git pull vs fetch, Git fetch is a safer alternative because it pulls in all the commits from your remote but doesn't make any changes to your local files. On the other hand, Git pull is faster as you're performing multiple actions in one – a better bang for your buck.


1 Answers

You can simply specify the full refspec when pushing:

git push origin 17081fa:branchname
git push origin 30854d2:branchname
# etc

If you want to automate it a bit, you could write a litte shell loop which waits for your keypress:

for hash in $(git rev-list 17081fa^..12ba64e); do
  read -p "Pushing $hash. Press return to continue.";
  git push origin $hash:branchname;
done
like image 185
knittl Avatar answered Nov 11 '22 19:11

knittl