Skip to content

Instantly share code, notes, and snippets.

@mehmetkurt
Last active May 19, 2023 11:31
Show Gist options
  • Save mehmetkurt/9a590b680751c445f56f1095dbcc6be9 to your computer and use it in GitHub Desktop.
Save mehmetkurt/9a590b680751c445f56f1095dbcc6be9 to your computer and use it in GitHub Desktop.
Git Cheat Sheet

subscribe on youtube

Create a new git Repository to local

git init

Clone repository from local

git clone path/repo

Clone repository from remote

git clone http://url/repo/projectname(.git)

or with ssh

git clone username@server:repo/projectname(.git)

Clone Branch from Specific Branch in Remote

git clone --single-branch --branch branchname host:/dir.git

Reset Changes after pull brach

git fetch --all
git reset --hard origin/develop
git pull origin develop

How to remove node_modules on git

  1. Create a .gitignore file in the git repository if it does not contain one

touch .gitignore

  1. Open up the .gitignore and add the following line to the file node_modules/
  2. Remove the node_modules folder from the git repository

git rm -r --cached node_modules

  1. Commit the git repository without the node modules folder

git commit -m "Removed node_module folder"

  1. Push the repository to github

git push origin master

  1. After all of that, you should also add the gitignore and commit it to the repository

git add .gitignore
git commit -m "Updated the .gitignore file
git push origin master

Delete a remote GIT branch

To delete a remote branch you can use the following command:

git push <remote_name> --delete <branch_name>

or

git push <remote_name> :<branch_name>

Delete a Local GIT branch

To delete a local branch you can use the following command:

git branch -d branch_name

or

git branch -D branch_name


as you can see above, we have 2 different argument, one with ‘d’ and one with ‘D’.
The -d option stands for --delete, which would delete the local branch, only if you have already pushed and merged it with your remote branches.
The -D option stands for --delete --force, which deletes the branch regardless of its push and merge status, so be careful using this one!

Stop tracking files that should be ignored

To stop tracking the files in the ignore file open a command prompt and navigate to the directory that contains your solution file (.sln) and run the following commands.

git rm -r --cached .
git add .
git commit -am "Remove ignored files"

That seemed to do the trick for me. The git commands I found here. If you click on that link you will see there are lots of options on which commands to use for this process. If the above doesn’t work for you one of the other answers should meet your needs.

In the future I will be making sure my ignore file exists first just to avoid any issues.

Pull from remote auto merge

git pull -s recursive -X theirs remote-repo-url remote-branch --allow-unrelated-histories

subscribe on youtube

@mehmetkurt
Copy link
Author

Do you want to add git cheat in this file? What are you waiting for? Write a comment and add your cheat.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment