Github
Title | Code |
---|---|
|
1st create a folder for git on pc Basic configration... $ git init create .git file $ git --version $ git config --global user.name "Aslam" $ git config --global user.email "aslam@gmail.com" $ git config --list clear Each of every project user & email $ git config user.name "aslam" $ git config user.email "aslam@gmail.com" upload file... $ git status $ git add file.txt [save this file] $ git add --all or $ git add . $ git commit -m "message" $ git remote add origin https... $ git push -u origin master download file... git status git log first create a folder... git clone https link... update..... git status git add . git commit -m "message" git log git pull git push [upload to master branch] log [list of commit] $ git log $ git log --oneline download from branch create a branch first in git hub... git clone https link... -b branchName branchName= about, help, contact etc |
|
switch go any repository or branch git checkout a1b2c3 How to switch back to 'master' with git? git stash or git commit -m "abcd" git checkout master git branch -D merchantApi Note: Above steps will delete the branch locally. For deleting the branch you have to stash the changes made on the branch or you need to commit the changes you made on the branch. Follow the below steps if you made any changes in the current branch. |
|
2nd commit : 2020 1st commit : 1010 --------------------- git reset --hard 1010 git push --force |
|
Local check git config user.name git config user.email ----------------------- Global check git config --global user.name git config --global user.email ----------------------- Change local git config user.name "gitHub-UserName" git config user.email "gitHub-email" ----------------------- Change global git config --global user.name "gitHub-UserName" git config --global user.email "gitHub-email" |
|
github set project url ->git remote set-url origin [repository link] example: https://github.com/aslamcsebd/project.git github show project url ->git remote show origin https://mhagemann.medium.com/how-to-fix-ssh-permission-denied-with-git-clone-f669b65f90ac |
|
git commit --amend -m "New commit message" |
|
git fetch origin [commit no] git checkout FETCH_HEAD |
|
git reset commitNumber --hard |
|
git reset --soft HEAD~1 |
|
git remote set-url origin https://github.com/projectName.git git push -u origin main |
|
create branch => git branch anyName edit branch You edit branch which branch you stay => git branch -m newName delete branch You don't delete this branch which branch you stay now. => git branch -d branchName Switch any branch => git checkout branchName branch status see => git branch ->dev ->*main [(* icon) means you are now stay main branch] N:B: You are now [main branch] and you have 3 commit. when you create [dev branch] the main branch's all commit copy from main to dev branch. So you should work now dev branch and when you have 5 commit you can merger the main branch. But if you want to dev branch merge, you stay now main branch and pull/copy code from dev branch. => git merge dev git merge: if you are now main branch with no code or commit, but want to merge/copy from another/dev branch. In locally pc ------------- git merge origin dev --allow-unrelated-histories from server/cloud ----------------- git pull origin masterOrDev --allow-unrelated-histories N:B: if you want default main branch to dev, it working in the github server. There are many option to rename, default any branch as root/main branch. |
|
git config --global --unset user.name git config --global --unset user.email git config --global --unset credential.helper cmdkey /delete:LegacyGeneric:target=git:https://github.com git config --global user.name “username” git config --global user.email emailaddr git config credential.helper ‘store’ git remote add origin repolink git remote -v git init git add . (Stage) git commit -m “message” (Commit) git push origin master (Push) https://www.youtube.com/watch?v=HGfT8JFkC2I |
|
git reset --hard |
|
open terminal root folder open .ssh folder or create cmd: ssh-keygen -o -t rsa -C githubEmail see: ls cmd: open id_rsa.pub copy then add : https://github.com/settings/keys also use: ssh-keygen -t ed25519 -C "your_email@example.com" for small key |
|
use Illuminate\Support\Facades\Log; public function gitInfo() { $branch = trim(shell_exec('git rev-parse --abbrev-ref HEAD')); $commitHash = trim(shell_exec('git rev-parse HEAD')); $commitMessage = trim(shell_exec('git log -1 --pretty=%B')); return response()->json([ 'branch' => $branch, 'commit_hash' => $commitHash, 'commit_message' => $commitMessage, ]); } |
|
git rm --cached .env git commit -m "Stop tracking .env" git push |
|
My goal: Push an existing Git project (committed as user1) To a new GitHub account (user2) But show commit history as if it was from user2 instead of user1 And right now GitHub is denying access, because the commits are still under user1 and Git is trying to push using that account. Keep commit history but change author info to supremeGlobal # Step into your project cd /var/www/html/supreme # Rewrite all commits to a new author git filter-branch --env-filter ' OLD_EMAIL="old@example.com" CORRECT_NAME="supremeGlobal" CORRECT_EMAIL="supremeglobalbd@gmail.com" if [ "$GIT_COMMITTER_EMAIL" = "$OLD_EMAIL" ] then export GIT_COMMITTER_NAME="$CORRECT_NAME" export GIT_COMMITTER_EMAIL="$CORRECT_EMAIL" export GIT_AUTHOR_NAME="$CORRECT_NAME" export GIT_AUTHOR_EMAIL="$CORRECT_EMAIL" fi ' --tag-name-filter cat -- --branches --tags Replace OLD_EMAIL with your actual old email (from git log) git log Author: user2 <user2@gmail.com> git remote remove origin git remote add origin https://user2:your_classic_token@github.com/supremeGlobal/supreme.git git push -u origin main --force |