#Git notes
-
git init
: initialize current folder as a git repository -
git clone <URL>
: brings the git repo from to current folder -
git status
: tells us waht we need to know about our curreent repository -
git add <FILES>
: add to the staging area -
git commit
: open a text editor to write commit message -
git commit -m
: "MESSAGE":write message as a commit wthout a text editor required -
git log
: shows the log (history) of our commits -
git log --oneline
: shows the shorter oneline commit -
git diff
: compare current uncommited state with last known git state -
git diff --staged
: runs git diff between the stafging area and last known state -
git diff HEAD~<NUMBER>
: compares HEAD with commit age (relateive) -
git diff <HASH>
: compared HEAD with the commit in -
git restore --source <HASH OR HEAD~> <FILE>
: restore files to <HASH OR HEAD~> -
git checkout <HASH OR HEAD~> <FILE>
: restore files to <HASH OR HEAD~> -
git checkout <HASH OR HEAD~>
: if you forget the file, you end up in detach> -
git checkout main
: go back to main -
git switch main
: go back to main commit
warning: LF will be replaced by CRLF in README.md the file will gave its original line endings in your working directory
#adding conflicting changes
git remote add <NAME> <URL>
: adds the as a remote with the name is by convention called origingit remote rm <NAME>
: to removes the remote calledgit remote -v
: looks at all the remote you havegit push <WHERE> <WHAT>
: pushes the branch togit pull <WHERE> <WHAT>
: pulls the branch in to local computer
git branches <NAME>
: create branch where you are (HEAD)git switch <NAME>
: move to the branchgit checkout <NAME>
: also move to hte branchgit switch -c <NAME>
: also create and move to branch in 1 command
##sec_branch added lines
git branches <NAME>
:this comment is from second branch
Let's say we are working on our main branch & writes commits on new branch as well as main branch during this process we made change to the same line to the same file now we will have a conflict and its resolution is very similar to the process when we had to synchronize our work from our local computer to our remote GitHub.
There are few ways we can fix our conflicts, using a - git command called rebase
. - What rebase is doing
is - rewriting the history of commit
.
git rebase <Other Branch>
: To incorporate changes from to current BRANCH.
trying toc commit change from VS code NOw ltes see
again trying to do changes in second line as well to see git working let see start