Skip to content

Instantly share code, notes, and snippets.

@cahitihac
Last active April 1, 2019 17:47
Show Gist options
  • Save cahitihac/bc2efa4dadc9e4f15fb2147de8576322 to your computer and use it in GitHub Desktop.
Save cahitihac/bc2efa4dadc9e4f15fb2147de8576322 to your computer and use it in GitHub Desktop.
Useful Git Commands
You have made same changes in a file (or multiple files) and you want to discard the changes without commiting.
You either want to dicard the changes in a single file or all changes in all the files.
If your intention is to discard changes in a single file then do the following;
git checkout -- <file-name>
If your intention is to discard changes in all files then do the following;
git checkout -- .
---
You have created a branch but then realised that you made a mistake. Now, you want to rename it. You've got two options;
Use the following if the branch that you wanna rename is not the current branch;
git branch -m <oldname> <newname>
Use the following if the branch that you want to rename is the current branch;
git branch -m <newname>
---
You have a large repo whose size is GBs. Then you may have some issues when cloning it to your local. You can use the following command to clone your project with a small part of your git history;
git clone --depth=1 <remote_url>
Once you have cloned your repo, you can complete your history by doing;
git fetch --unshallow
or
git fetch --depth=<an integer value that shows number of commits>
if it doesn't work with a big value, then try a small value and keep increasing it as each command completes fetching
---
git pull
git pull --rebase
git rebase
git merge
git tag
git checkout
git branch name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment