Git Intro PDF
Git Intro PDF
Assume you are developing a software application. As you Commit is a local operation that captures a snapshot of your
progress with your coding, you eventually reach a point where changes in the repository. First, add the files that you want to
you have a working version. At this stage, you would like to commit to the staging area:
save your progress as a milestone. This is crucial because as you
continue developing, you might introduce changes that cause git add .
conflicts, potentially breaking your code. If this happens, hav-
ing a saved milestone allows you to revert to a previous stable
The above command adds all the files to the staging area.
state, saving you from the frustration of fixing complex issues.
Mention name of file at the place of dot for specific ones.
Here comes Git to maintain the milestones. The process has Now, take the snapshot. When you commit, you are recording
two steps 1) staging: select which files to track, 2) commit: changes to the local repository with a message describing what
record the staged changes with a log message describing the was changed. This message helps you and others understand
current state of the code. the purpose of the changes:
In a big project when multiple programmers collaborate on
the same codebase, it is beneficial to host the code on a central
git commit -m "Initial commit"
server like GitHub. It needs to manually create an account and
repository at GitHub. Collaborators can get the code from this
repository on their local system using clone. Now they will Similar to the add command, you can use reset to remove
develop code on their local system and send updates to GitHub files from the staging area:
when reached to a milestone.
git reset file01.py
1.1 Initialisation We can use status command to get overview of which files
are staged and which are not.
Git init creates a new local repository in a folder.
git status
git init
To add remote directory with remote Now, see the log to get an overview of the commits:
1
1.4 Fetch This command combines git fetch and git merge in one
step. It fetches changes from the remote repository and imme-
The fetch command retrieves changes from the remote repos- diately merges them into your current branch.
itory to the local repository. It is used to download commits,
files, and references from a remote repository into your local
repository without merging them with your local branches. It 2 Undo and Redo Changes
updates your remote-tracking branches but does not modify
your working directory or current branches. This allows you to Locate a commit by typing git log and identify its hash. The
see what others have been working on without affecting your reversal can be done using:
local work.
Inspect the changes fetched using commands like git log git revert <hash-code>
origin/main or git diff origin/main. If you want to incor-
porate those changes into your local branch, you would typically This will create a new commit that undoes changes related
use git merge or git rebase. to the provided hash code. Another command is reset:
A modifier -f tells that the local branch is correct and that it git merge newBranchName
should force the override of the remote one.
git push -f
4 More commands
A local branch when pushed to master need to tell where to
puch the same. git diff sourceBranch targetBranch: shows the difference
between two branches.
git push -u origin newBranchName git tag: creates a sna[shot of the project at a certain time.
git stash: moves the changes of the project into a stash.
git stash pop: retrieves changes from the stash and applies
them.
1.7 Pull git rebase: takes the commits that happened in the original
branch and applies them into the current branch before the
The pull command retrieves commits from the central reposi- current changes.
tory to the local project: git clean: removes untracked files.
git pull