Tuesday 1 September 2020

2022 GIT Checkout local, create remote based on local. Conflicts. Change linux windows password (Updated *****) && delete git local and remote branch

First clone master repo

git clone url (HTTPS) 

git clone url (SSH)



// Cloned empty remote repo

https://stackoverflow.com/questions/4181861/message-src-refspec-master-does-not-match-any-when-pushing-commits-in-git


git checkout -b master

touch README

git add .

git commit -m "init"

git push -u origin master



Checkout

 // NOTE: With update, when a repository has been created, git has a default remote branch of main or master. Git changed to main 

(https://stackoverflow.com/questions/24114676/git-error-failed-to-push-some-refs-to-remote)

So when repository is cloned to local, you are already on local branch main. Just add a file gitignore, README.md, then

git add .

git commit -m "init"

git push

This will directly push to remote/main branch


// Non main branch

1.       git checkout --track origin/branchA (create local branch branchA based on remote branch origin/branchA, then set up tracking to remote origin/branchA

*

2.       git checkout –b JX-dev(Create local branch JX-dev, based on local branch branchA)


//

3.       git push –u origin JX-dev(set upstream to local JX-dev to remote JX-dev, if remote doesn’t have it , create remote branch origin/JX-dev, then set up tracking)


D

 Delete 

https://www.freecodecamp.org/news/how-to-delete-a-git-branch-both-locally-and-remotely/#:~:text=//%20delete%20branch%20locally%0Agit%20branch%20%2Dd%20localBranchName%0A%0A//%20delete%20branch%20remotely%0Agit%20push%20origin%20%2D%2Ddelete%20remoteBranchName

// delete branch locally

git branch -d localBranchName


// delete branch remotely

git push origin --delete remoteBranchName


Merge

1.       git checkout branchA(Switch to local branch branchA)

2.       git pull(update branchA from remote)

3.       git merge origin/JX-dev( merge with remote JX-dev)

4.       git push

https://www.git-tower.com/learn/git/faq/checkout-remote-branch

https://stackoverflow.com/questions/24301914/how-to-create-a-local-branch-from-an-existing-remote-branch


Conflicts:

Git merge origin/branch

 

// No conflict

Git push

 

// With conflict

// Fix conflict

Git add .

Git commit –m  ‘fixed”

Git push

How to reset windows local credentials for git :

 

https://cmatskas.com/how-to-update-your-git-credentials-on-windows/

 

How to reset linux local credentials for git:

 

https://stackoverflow.com/questions/20195304/how-do-i-update-the-password-for-git


No comments:

Post a Comment