Skip to content

Instantly share code, notes, and snippets.

@FlorianWolters
Last active October 11, 2015 00:38
Show Gist options
  • Save FlorianWolters/3775542 to your computer and use it in GitHub Desktop.
Save FlorianWolters/3775542 to your computer and use it in GitHub Desktop.
Git command line examples

Record changes to the repository.

git commit -a -m "Merged with local develop branch."

Add a tag and push all tags.

git tag -a v0.1.0 -m "version 0.1.0-stable"
git push origin --tags

Remove a remote tag.

git tag -d v0.1.0-stable
git push origin :refs/tags/v0.1.0-stable

Update branch to another branch

git checkout master 
git reset --hard develop

Update master to develop branch

git checkout master
git merge --no-ff develop

Delete a remote commit.

Reset to a specific commit, <commit-before-head> is e.g. 1.

git reset --hard HEAD~<commit-before-head>

or

git reset --hard <sha1-commit-id>

Force push the changes:

git push origin HEAD --force

Delete a local branch.

git branch -D <branch>

Delete a remote branch.

IMPORTANT: Do not forget do select another branch as the default branch on GitHub!

git push origin --delete <branch>

Create a branch and switch to it at the same time.

git checkout -b <branch>

Merge "develop" branch into "master" branch.

git checkout master
git merge develop

Create the "gh-pages" branch.

git checkout --orphan gh-pages
git rm -rf .
git add .
git commit -a -m "Initial pages commit."
git push origin gh-pages

Setting the current branch to the remote branch.

git fetch origin
git reset --hard origin/master

Update all submodules.

git submodule foreach git reset --hard
git submodule foreach git pull origin master
git submodule foreach git submodule update --init --recursive
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment