Skip to content

recentlyhatched/git

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 

Repository files navigation

Notes

Merge Main into Greet Branch

git merge main

Switch to main branch and make changes to hello.sh file

git checkout main

Merging Main into Greet Branch (Conflict)

git checkout greet git merge main

Resolve the conflict (manually or using merge tools)

git mergetool - this was automatic for me in vs code

After resolving, stage the changes and commit

git add git commit -m "commit message"

Rebasing Greet Branch

git checkout greet git rebase main

Merging Greet into Main

git checkout main git merge greet

Unstage a file

git rm --cached <file> deletes the file from staging and makes it "untracked"

Stage specific lines of code for commit

git add --patch <file>

Display last two commits

git log -n 2

Display commits in the last 5 mins

git log --since="5 minutes ago"

git command to show git commit in this format

"* e4e3645 2023-06-10 | Added a comment (HEAD -> main) [John Doe]" git log --format='%h %ad | %s [%an]' --date=short HEAD -1

Go back to lastest commit

git checkout <master/main>

List tags

git tag

Create tag for current version

git tag -a tag-name -m "tag message"

Create tag for parent commit

git tag -a tag-name -m "tag message" HEAD~ or maybe HEAD~1 at the end for one before most recent commit i.e. parent commit

Switch to a commit using tag name

git checkout tag-name

Delete commits

git reset --hard tag-name or git reset --hard <hash> where hash is the commit aplhanumerical value

Display logs with deleted commits

git fsck --lost-found and/or git log --all --oneline --graph --decorate

Clean up commits

Delete branches/tags pointing to those commits

  1. git branch -D unwanted-branch
  2. git tag -d unwanted-tag

Clear Reflogs

  1. git reflog expire --expire=now --all as git keeps logs even for deleted branches - this clears them

Run aggressive garbage collection

  1. git gc --prune=now --aggressive

Verify deleted commits are gone

1a. git checkout tag-name or git checkout <hash> OR 1b. git log --all --oneline --graph --decorate

Other

Update last commit with new changes

git commit --amend -m "new commit message"

git rev-parse HEAD # Get latest commit git cat-file -p HEAD # Inspect commit object git ls-tree HEAD # View top-level tree git ls-tree HEAD:lib # View contents of lib/ git show HEAD:lib/hello.sh # View content of hello.sh

View branch strucutre before commiting

git log --all --decorate --oneline --graph

Merge main branch into current branch

git checkout <branch-name> git merge main

Reset branch to last commit

git reset --hard HEAD~1

Clone a repository

git clone <url> OR git clone <directory> <destination>

Get changes and merge

git fetch and then git mergeOR git pull

Create local branch from remote

git checkout -t origin/<remote-branch-name> - also try git checkout <remote-branch-name>

Verify branch tracking

git branch -vv - literally "branch"

Add new remote repository

git remote add <remote-name> <url>

Push branches to remote

git push <remote-name> <branch-name>

Verify remote configuration

git remote -v

Create bare repo copy of repository

git clone --bare <source-repo-direcrory-path> <bare-repo-name>.git

Add bare repo to as a remote to a repository

git remote add <name-bare-repo-here> <bare-repo-name>.git git remote -v

Upstream branch: To push the current branch and set the remote as upstream, use

git push --set-upstream <bare-repo-name> <master-or-main-or-prod>

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors