Belajar Menggunakan Git dan Daftar Cheat Sheet-nya

Belajar Menggunakan Git dan Daftar Cheat Sheet-nya

Berikut meruapakan beberapa catatan pribadi saya ketika belajar GIT

 

## Inisiasi Git

 git init

 

## Edit git configuration

Run

 git config --global user.email "[email protected]"

 git config --global user.name "Your Name"

to set your account's default identity.

Omit --global to set the identity only in this repository.

https://help.github.com/articles/setting-your-commit-email-address-in-git/


 

## Git check remote url

git remote show origin

https://help.github.com/en/articles/renaming-a-remote

 

## Remove all modified data

# Revert atau reset git

https://docs.gitlab.com/ee/topics/git/numerous_undo_possibilities_in_git/

 

## Undo yang sudah di edit

git reset --hard

git reset

git rm --cached filename.txt


 

## Menyimpan yang sudah di edit sebelum di commit

git stash

git stash list

git stash clear

git stash drop [email protected]{1}

git stash apply [email protected]{0}

https://medium.freecodecamp.org/useful-tricks-you-might-not-know-about-git-stash-e8a9490f0a1a

### Git stash with message

git stash save <message>

git stash -u

git stash --include-untracked

git stash save -u <message>

https://dev.to/neshaz/how-to-git-stash-your-work-the-correct-way-cna



 

## Delete branch local and remote

https://stackoverflow.com/questions/2003505/how-do-i-delete-a-git-branch-both-locally-and-remotely


 

## Get differential with branch

git diff --name-status master

git diff --name-status firstbranch..yourBranchName

git diff --stat --color master..branchName

git diff --stat --color branchName..master

git diff --stat --color master..development

git diff --stat --color production..development

https://stackoverflow.com/questions/822811/showing-which-files-have-changed-between-two-revisions


 

## Merging git

git checkout ba

git checkout -b ba-merge

git merge master

.... review new code and fix conflicts....

git commit

git checkout ba

git merge ba-merge

git branch -d ba-merge

git push origin --delete login

git merge master


 

## Menambahkan remote repository kalau belum pernah

git remote add origin [email protected]:ymukti/citilink-dashboard.git

https://help.github.com/articles/adding-a-remote/


 

## Ubah remote repository URL

https://help.github.com/articles/changing-a-remote-s-url/

git remote -v

git remote set-url origin https://github.com/USERNAME/REPOSITORY.git


 

## Delete remote repo

git remote rm bitbucket


 

## Menggunakan git tag untuk release version

https://dzone.com/articles/git-tags-version-control-made-easy

https://git-scm.com/book/en/v2/Git-Basics-Tagging

git tag -a v0.1.0 -m "Releasing version v0.1.0"

git push origin v0.1.0


 

## Git pull error => fatal: refusing to merge unrelated histories

git pull origin branchname --allow-unrelated-histories

git pull origin master --allow-unrelated-histories


 

## Melihat log

git log --pretty=oneline


 

## Adding SSH key to git

https://help.github.com/articles/adding-a-new-ssh-key-to-your-github-account/

Harus buka git bash

clip < ~/.ssh/id_rsa.pub


 

## Get all remote brances

https://stackoverflow.com/questions/10312521/how-to-fetch-all-git-branches

git fetch --all

git pull --all

git pull -u origin --all


 

## Git ignone not working

https://stackoverflow.com/questions/11451535/gitignore-is-not-working

git rm -r --cached .

git add .

git commit -m "fixed untracked files"


 

## Git fatal: The current branch master has no upstream branch

git push -u origin master

git push -u origin --all


 

## Git delete last commit push

https://stackoverflow.com/questions/1338728/delete-commits-from-a-branch-in-git

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

git push origin HEAD --force


 

## Updates were rejected because the tip of your current branch is behind

## Updates were rejected because a pushed branch tip is behind its remote

# rebase in progress; onto bc631e1

You are currently rebasing branch 'dev' on 'bc631e1'

  • Step 1: Keep going git rebase --continue

  • Step 2: fix CONFLICTS then git add .

  • Back to step 1, now if it says no changes .. then run git rebase --skip then go back to step 1

  • If you just want to quit rebase run git rebase --abort

  • Once all changes are done run git commit -m "rebase complete" and you are done.

 

## Remove branch

### Deleting local branches in Git

git branch -d feature/login

### Deleting remote branches in Git

git push origin --delete feature/login

 

## Git Cheat Sheet