You are on page 1of 8

Git & GitHub

Basic Introductory

Resources to https://docs.github.com/en/get-started/quickstart/git-and-github-
follow learning-resources

Status Ongoing

git config --global user.name "asadpro" this command is used to set the
git config
username and email. git config --global user. email "asadjani202@gmail.com"

git init will initilize a git repository locally

command will add all the file in current directory to the git folder locally not to
git add .
github
Between commas put your message to show changes to corresponding
git commit -m ‘ ’
commit. git commit --amend option will edit the commit
git push this will push our project to remote location where our project is hosted.

now here master is the location of our git folder on our local machine where
git push origin
origin is the branch of our project on github to which we are going to push the
master
project .
git status will show us the status of our project.

git remote add github.com/genf/.comthe link to the new repository of github. this command

Git & GitHub 1


origin will tells that add these folder to the given github link which is on remote
location from our local location

it shows that any remote repository that i connected to this repo on which we
are currently work on.now after that we can press the command git push

git remote -v origin master now for the sake of simplicity we can use ( git push -u origin

master ). git remote will show you all the remote repository we can change
remote repo name by git remote rename old newName

git branch will show us the branches of our repo.

this will create a new branch and also switch to it as well at the same time
git checkout -b
which can be then merge with master branch by using  the command ( git
branchname
merge master )
git checkout
this command is used to switch between branches.
master

git branch -d
this command will delete the branch from tree.
branchname

will show us the added on unadded file to the git repo. it can be useful
git diff before commiting any changes to the repository or adding anything to
the repository.

this will add and commit at the same time but this will work only for
git commit -am modified file not for newly created file because if you have created a new
"mesage" file then we have to first stage it with git so git will know about it then we
can use that command.
for undo the change to the git repo by git add command you have to only put
git reset filename git reset filename or we can only put git reset which will undo only the
operation you have done previously.
Learning writing https://docs.github.com/en/github/writing-on-github/getting-started-with-
styling on gitHub writing-and-formatting-on-github/basic-writing-and-formatting-syntax
git help -a this command will show us command and their usage.

this command will shows all the usage and help commands related to
git add --help add command. we can replace add with other command like push, pull &
so on.
this command will undo all the changes you have done by acident or someone
else did then by running this command you can recover that modified file to
git checkout -f
clean tree but this command will undo changes only to our local working tree.
Also we can use Git checkout to see our working tree.
git diff if we do changes in a file then run this command what it will do is to show us
the difference b/w the updated and old file. actually this command will

Git & GitHub 2


compare the staging area and working area of git. but if we run git add -A

then changes of working area would be add to staging area and git diff will
show nothing.

this command is used to check last 1 commit. if we have hundred and


thousands of commit then we can check previous commits by replacing 1 with
git log -p -1
any number you want. which will return last commits corresponding to that
specified number.

this command will remove the file whereas git rm --cached waste.html
git rm

command will only remove the modified file from staged area and will leave it
git rm --cached as untracked file in working directory then we can check it in working area by
waste.html but in case we change our mind then we can restore again by this
git status

command git restore --staged waste.html to restore it from working tree git
restore --worktree waste.html

this command will show us status in short form. e.g. do changes in 2 different
files and then check it status by following -s option which stands for short then
git status -s this command will show us modified file by red M . and if we add that modified
file to staging area then by running the same command will show you M (in
green color) which means it is in staging area now.
https://www.notion.so/Git-GitHub-
1a31adbb0c0e4dcb9f8b7df996a264c0#c127ca3cc2db46fca36f606076143e8d
working tree &
working tree is the area in which we are currently working in simple it’s our
staging git
project folder while staging area aka index is the area which take a snapshot
repository
of changes we made in our project folder by command git add -A (this
command add all the changes to the staging area)
.gitignore file container all the files which are no useful to git like logs file etc.
we can simply create .gitignore file and insert the name of file in it and it will
.gitignore
ignore that folder from being commit to stage area but in flutter it’s create by
default untrack all the uneccessary files to git.
this command will change branch name to the new one. git checkout -b
git branch -m
brancName vs git branch newBranch above two command do the same but first
oldName
one will create branch as well switch to that branch also but second command
newName
will only create a new branch.
this command will shows us from which repository we are pulling and
git remote -v
pushing repos. git remote
git remote add git remote add origin git@github.com :asadpro/The-Boring-Show-Day-1.git this
origin command will gives name to this gihub url as origin.
git push origin
this command will push master branch to origin (our github repo)
master

Git & GitHub 3


SSH or GPG SSH and GPG keys allows our local file to connect with github account and
the changes we made in our local repository will take effect in github
repository.

creating new git checkout -b newBranch this command will create a new branch git push -

branch and push u origin newBranch this command will push that new branch to
it to the github origin(github repository).
git commit --
this command will update the commit message.
amend
git revert HEAD this command will revert changes and will add new commit is
created with inverse changes. This cancels previous changes instead of
making it as though the original commit never happened. It’s a bit like an undo
command. if we multiple commit in our repo suppose 25 and you want to
git revert HEAD change the commit of 18 then we can’t simply change it using head instead
we can use the key like git revert 2cb99d7251a7013b6535ab5a50f332e28f2f978a. or
we can only specify first few characters of key.git revert will create a new
commit to reverse the previous one, and is the best option for undoing
commits on public branches.

this command will delete the commit completely and then git push origin
git rebase -i
master --force command will push changes forcefully and delete all previous
HEAD~1
commits.

this command will show you


git show 2cb99d7251a7013b6535ab5a50f332e28f2f978a

the commit message. these random numbers are calculated hash value of
git show
commit we have done before. to revert changes in that commit run git revert

2cb99d last character define the hash value above.

git diff this command will check all the changes made to particular branch. In short, it
branch1..branch2 will show you all the commits that “branch2” has that are not in “branch1”.

git merge conflicts occur when we do changes in two branches main &
newBranch at the same place and did not add those changes. then this issue
git merge
occur. after that to resolve conflict issue we have to add those changes and
conflicts
commit them individualy. If there are merge conflicts (meaning files are
incompatible), --abort can be used to abort the merge action. git merge --abort

git log --graph --


This shows a summarized view of the commit history for a repo.
oneline
git config --
global allows us to configure the credential
git config --global credential.helper cache

credential.helper helper, which is used for Allowing automated login to GitHub


cache
git remote show this command will show you all the commit happen to the remote repository.

Git & GitHub 4


origin

this command synchronize local repository with remote repository on


git fetch
github.com.

this command will check for the refs folder in git and will also look for others
find .git/refs
files inside it.

git reset will reset the head to specific commit by using that commit
git reset --hard
reference which we can see git reflog or git log —oneline the other
<old-commit-id>
command git push -f remotename localrepo can be used to forcefully push local
git push -f
branch into remote branch. If you switch to previous commit locally but
<remote-name>
commits on remote are still exists and you want to push commits the same on
<branch-name>
local repo to remote repo then use this force flag for that git push origin master
git push --hard
-f this command will synchronize all the local commits to remote commits and
origin master -f
delete any others commits.

this command will give you all the old references log whether delete or not it
will show you all the previous reference. then those blue color references can
git reflog be used to switch to that specific commit by git reset —hard oldcommitid or git
reset --hard HEAD~2 this command will let us to previous last 2 commit. we can

also use reference id like git reset --hard b746a21.

git fetch fetches remote updates but doesn't merge; git pull fetches remote
updates and merges. Suppose if someone made changes in remote
git fetch vs git
repository and we want only see them first before merging them then we can
pull vs git remote
use git fetch if we okay with that changes then we can perform git push to
show origin
merge them with our local repository. The git remote show origin command will
tell you whether your local repo is updated or outdated.

Remove these markers <<<<<<<, =======, and >>>>>>> conflict markers


merge conflict when resolving a merge conflict. Conflict markers aren’t required when
resolving a merge conflict.
git push --delete this command will delete created branch from remote repo. To delete branch
main refactor from local repo use git branch -d branchName

This command is used to rebase the changes made in newBranch to the


master branch locally. Suppose we have two branches then changing in one
git rebase
file and not in other. To add those changes in other branch we have to use git
newBranch
or git rebase newBranch. But we mush have to be on master
merge newBranch

branch before merging or rebase.

git config --list -- this command will show us where our git configuration file exists on system.
show-origin git config --list will show you all the git configuration files.

username & $ git config --global user.name "John Doe" $ git config --global
email user.email johndoe@example.com. when these username and email once

Git & GitHub 5


set with —global option then these information will be used by git for every
other project but if we want give different email and username to a specific
project then run the same command without --global option with your own
username and email.

cloning a project
within specific git clone https://github.com/libgit2/libgit2 newFolder
folder

this command is used to show the status in short form or we can also use --
git status -s
short flag instead of -s

git branch --set-upstream-to <remote-branch> this command will set the


setting upstream
upstream for our current local branch.

git log --oneline --grep=first this command will grep those commits which
grep commit
contain the “first” word in their message.

this command will show the log history of lib folder. To know the log history of
git log -- lib
specific folder replace lib with folder name.

Git & GitHub 6


GitHub Basic Commands:
Git area and structure of saving a project

Creating a new branch and merging changes from temporary branch to master
branch also switching b/w branches etc. read below commands carefully as these
commands are done sequentially. git checkout newBranch command will switch us to
newBranch(duplicate of master branch). git merge newBranch this command will merge

Git & GitHub 7


all the changes of newBranch to master branch but first we have to switch to the branch
to which we want to merge that changes. git diff newBranch master this command will
show us the difference b/w both of the branches.

199 git branch -b newBranch


200 git branch newBranch
201 git branch
202 git checkout newBranch
203 git add -A
204 git status -s
205 git status
206 git commit -m "commit to newBranch no master"
207 git status
208 git checkout master
209 git merge newBranch
210 git status
211 git diff newBranch master
212 git checkout -f
213 git reset --Head
214 git reset
215 ls
216 git status
217 git reset --help
218 git reset -p
219 git reset --merge
220 git branch
221 git branch -d newBranch
222 git branch
223 history

git remote commands synopsis:

git remote [-v | --verbose]


git remote add [-t <branch>] [-m <master>] [-f] [--[no-]tags] [--mirror=(fetch|push)] <
name> <url>
git remote rename <old> <new>
git remote remove <name>
git remote set-head <name> (-a | --auto | -d | --delete | <branch>)
git remote set-branches [--add] <name> <branch>…
git remote get-url [--push] [--all] <name>
git remote set-url [--push] <name> <newurl> [<oldurl>]
git remote set-url --add [--push] <name> <newurl>
git remote set-url --delete [--push] <name> <url>
git remote [-v | --verbose]show [-n] <name>…
git remote prune [-n | --dry-run] <name>…
git remote [-v | --verbose]update [-p | --prune] [(<group> | <remote>)…]

Git & GitHub 8

You might also like