Skip to content

Git cheat sheet

Qais Patankar edited this page May 26, 2019 · 13 revisions

Here are some quick use cases for users of the git command-line tool. Use this as a quick reference guide if you’re looking for specific actions.

Be sure to check out the Git in a Nutshell guide as well.

Creating a local copy of a remote branch

Creates a local copy of a remote branch (e.g. “untested”). This can be useful if you want to switch to another branch, as only the default branch (e.g. “merge”) is checked out by default. This creates and switches to your new local branch “untested” (based on the remote branch of the same name) and pulls in the latest changes.

git checkout --track -b untested origin/untested
git pull origin untested

Pulling the latest changes from multitheftauto/mtasa-blue

If you want to stay up-to-date with the latest development you will want to pull in the latest changes from our multitheftauto/multitheftauto repository into your local repository.

git pull https://github.com/multitheftauto/mtasa-blue master

An easier way to do this is by creating a remote upstream and then pulling from that.

git remote add upstream https://github.com/multitheftauto/mtasa-blue
git pull upstream master

We recommend you to enable “pull rebasing” so that you don’t make unnecessary merge commits.

git config --global pull.rebase true # Do this once to apply it to your user account on your computer
git config pull.rebase true # Or do this once, per repo

Resetting your local branch to the latest on GitHub

Sometimes you just want to discard all your local changes and reset to the latest HEAD on your GitHub remote repository. Here’s how to do it for the “merge” branch.

git fetch origin merge
git reset --hard FETCH_HEAD

Resetting your local master branch to the latest on GitHub

This assumes you have the multitheftauto/mtasa-blue repo named as the `upstream` remote.

Take care with running these commands, as it will get rid of any changes on your local master.

git fetch upstream # to update your copy of upstream
git checkout master # to make sure you're on master
git reset upstream/master --hard # to reset your current branch (master) to upstream/master
git push # --force might be needed if you wrote to master

Note that --force deletes commits, and so is dangerous. Only do it if you’re sure you want to get rid of commits

Picking out individual commits from another branch

More information here: git ready – pick out individual commits

Checking out a tag

If you want to check out a tag (e.g. 1.0.3-Release), do the following:

git pull
git checkout -b 1.0.3-Release tags/1.0.3-Release
Clone this wiki locally