git第一次關(guān)聯(lián)遠(yuǎn)程庫并上傳文件
1.cd 指定目錄 2.git init 3.git add --all //add所有文件
4.git status 查看一下狀態(tài) 5. git commit -m 'first commit'
6.git remote add origin https://xxxxxxxxxxxx.git(遠(yuǎn)程庫地址)
7.git push -u origin master
以git的某個遠(yuǎn)程分支為節(jié)點創(chuàng)建一個新的分支特碳,并推送的遠(yuǎn)程分支
1诚亚、復(fù)制一個遠(yuǎn)程分支git checkout remotes/origin/remoteBranchName(遠(yuǎn)程分支名稱) -b localBranchName(新建本地分支名稱)
2、把本地分支推送到遠(yuǎn)程git push origin localBranchName(本地分支名稱):localBranchName(遠(yuǎn)程分支名稱)
git創(chuàng)建一個空白分支
1.創(chuàng)建并切換新分支
git branch <new_branch>
git checkout <new_branch>
git rm --cached -r .
git clean -f -d
2.創(chuàng)建空的commit
git commit --allow-empty -m "[empty] initial commit"
3.推送新分支
git push origin <new_branch>
Git 配置用戶名测萎、密碼
在終端輸入:
git config --global credential.helper store
然后Git pull一次亡电,輸入一次用戶名密碼就會自動保存該用戶名密碼届巩;
查看配置的用戶信息:
git config --list
Git從遠(yuǎn)程url下載工程
1.先創(chuàng)建一個文件夾mkdir xxxx
2.切換的新創(chuàng)建的文件夾分別執(zhí)行如下命令:
git init
git remote add origin url
git fetch —all
git checkout -b branchname origin/branchname
Git向遠(yuǎn)程提交代碼
git pull
git add --all
git commit -m "本次提交了什么內(nèi)容"
git push -u origin master
創(chuàng)建tag
git tag -a 2.1.0 -m "commit message" (2.1.0為版本號)
git push origin master
git push origin --tags
git push 報 HTTP Basic: Access denied 錯誤
原因:
本地git配置的用戶名硅瞧、密碼與gitlabs上注冊的用戶名、密碼不一致恕汇。
解決方案:
- 如果賬號密碼有變動 用這個命令 git config –system –unset credential.helper 重新輸入賬號密碼 應(yīng)該就能解決了
- 如果用了第一個命令 還不能解決問題那么 用這個命令:
git config –global http.emptyAuth true
3.如果以上兩個方法不起作用腕唧,那么采用以下方法:
進入控制面板》用戶賬號》憑據(jù)管理器或辖?windows憑據(jù)》普通憑據(jù),在里面找到git枣接,點開編輯密碼颂暇,更新為最新密碼之后就可以正常操作了。
Git刪除遠(yuǎn)程分支
git push origin --delete branch_name
Git cherry-pick用法
git fetch
git cherry-pick e5c72cd7b20fb77245aa82fef47f0278e3c4(某次提交sha值)
git push
git stash用法(代碼寫錯分支)
1.當(dāng)代碼在非目標(biāo)分支書寫時但惶,書寫完后執(zhí)行g(shù)it stash
2.切換到目標(biāo)分支耳鸯,git stash pop
3.執(zhí)行g(shù)it status查看一下
錯誤不足之處或相關(guān)建議歡迎大家評論指出,謝謝膀曾!如果覺得內(nèi)容可以的話麻煩喜歡(?)一下