User Tools

Site Tools


linux:git

This is an old revision of the document!


GIT

Check out remote branch

git switch --track origin/branch-name // 1. Creates a new local branch called branch-name
                                      // 2. Set its upstream to origin/branch-name (the remote branch)
                                      // 3. Move your working directory to that branch

Accidentally committed on master

If changes were accidentally committed on master and we want to move them to a new branch:

git switch -c new-branch         // Creates a new branch and switches to it.
git checkout master              // Go back to master
 
// Cleaning master - Option 1
 
git reset --hard origin/master   // This will delete the commit from master,
                                 // but it still exists on new branch
                                 // Resets to match the remote branch exactly.
                                 // Used to discard all local commits since last fetch/pull
linux/git.1761818942.txt.gz · Last modified: by v1ctor