deployment - Git command to checkout any branch and overwrite local changes -


is there git command (or short sequence of commands) safely , surely following:

  • get rid of local changes,
  • fetch given branch origin if necessary,
  • checkout given branch?

currently i'm stuck with:

git fetch -p git stash git stash drop git checkout $branch git pull 

but it's bothering me because i'm asked password 2 times (by fetch , pull). generally happy solution long password needed once.

a couple of notes:

  • it's part of homebrewed deployment script application (the code hosted on github),
  • there should no difference if branch fetched origin or not (i.e. first deployment of new branch shouldn't ideally require additional steps),
  • the script located on remote machine can accessed several people, hence no credentials stored , user/password must entered (but once if possible),
  • i don't care local changes, want pristine copy of given branch (the further part of deployment script produces local changes),
  • i can't clone or export fresh repository each time, takes time.

you follow solution similar "force git overwrite local files on pull"

git fetch --all git reset --hard origin/abranch git checkout $branch  

that involve 1 fetch.


Comments

Popular posts from this blog

Unable to remove the www from url on https using .htaccess -