Git Basics Vtu
Git Basics Vtu
Git Basics Vtu
What is Git?
Git is a distributed version control system (VCS) that is widely used for
tracking changes in source code during software development. It was created by
Linus Torvalds in 2005 and has since become the de facto standard for version
control in the software development industry. Git allows multiple developers to
collaborate on a project by providing a history of changes, facilitating the
tracking of who made what changes and when.
Here are some key concepts and features of Git:
1. Repository (Repo): A Git repository is a directory or storage location where
your project's files and version history are stored. There can be a local
repository on your computer and remote repositories on servers.
2. Commits: In Git, a commit is a snapshot of your project at a particular point
in time. Each commit includes a unique identifier, a message describing the
changes, and a reference to the previous commit.
3. Branches: Branches in Git allow you to work on different features or parts
of your project simultaneously without affecting the main development line
(usually called the "master" branch). Branches make it easy to experiment,
develop new features, and merge changes back into the main branch when they
are ready.
4. Pull Requests (PRs): In Git-based collaboration workflows, such as GitHub or
GitLab, pull requests are a way for developers to propose changes and have
them reviewed by their peers. This is a common practice for open-source and
team-based projects.
5. Merging: Merging involves combining changes from one branch (or multiple
branches) into another. When a branch's changes are ready to be incorporated
into the main branch, you can merge them.
6. Remote Repositories: Remote repositories are copies of your project
stored on a different server. Developers can collaborate by pushing their
changes to a remote repository and pulling changes from it. Common remote
repository hosting services include GitHub, GitLab, and Bitbucket.
7. Cloning: Cloning is the process of creating a copy of a remote repository
on your local machine. This allows you to work on the project and make
changes locally.
8. Forking: Forking is a way to create your copy of a repository, typically on a
hosting platform like GitHub. You can make changes to your fork without
affecting the original project and later create pull requests to contribute your
changes back to the original repository.
Git Installation
To install Git on your computer, you can follow the steps for your specific operating
system:
1. Installing Git on Windows:
a. Using Git for Windows (Git Bash):
• Go to the official Git for Windows website: https://gitforwindows.org/
• Download the latest version of Git for Windows.
• Run the installer and follow the installation steps. You can choose the default
settings for most options.
5. git status: Shows the status of your working directory and the files that
have been modified or staged.
6. git log: Displays a log of all previous commits, including commit hashes,
authors, dates, and commit messages.
7. git diff: Shows the differences between the working directory and the
last committed version.
8. git branch: Lists all branches in the repository and highlights the currently
checked-out branch.
9. git branch <branchname>: Creates a new branch with the specified name.
10. git checkout <branchname>: Switches to a different branch.
11. git merge <branchname>: Merges changes from the specified branch into the
currently checked-out branch.
12. git pull: Fetches changes from a remote repository and merges them into
the current branch.
13. git push: Pushes your local commits to a remote repository.
14. git remote: Lists the remote repositories that your local repository is connected
to.
15. git fetch: Retrieves changes from a remote repository without merging them.
16. git reset <file>: Unstages a file that was previously staged for commit.
17. git reset --hard <commit>: Resets the branch to a specific commit,
discarding all changes after that commit.
18. git stash: Temporarily saves your changes to a "stash" so you can switch
branches without committing or losing your work.
19. git tag: Lists and manages tags (usually used for marking specific points in
history, like releases).
20. git blame <file>: Shows who made each change to a file and when.
21. git rm <file>: Removes a file from both your working directory and the Git
repository.
22. git mv <oldfile> <newfile>: Renames a file and stages the change.
These are some of the most common Git commands, but Git offers a wide range of
features and options for more advanced usage. You can use git --help followed by
the command name to get more information about any specific command, e.g., git
help commit.
Experiment 1.
$ git init
1. Create a new file in the directory. For example, let's create a file named
"my_file.txt." You can use any text editor or command-line tools to create the file.
2. Add the newly created file to the staging area. Replace "my_file.txt" with the
actual name of your file:
Experiment 2.
Creating and Managing Branches:
Create a new branch named "feature-branch." Switch to the "master" branch. Merge
the "feature-branch" into "master."
Solution:
To create a new branch named "feature-branch," switch to the "master" branch,
and merge
the "feature-branch" into "master" in Git, follow these steps:
DBMS Notes
Database Management Systems94% (16)
41
12
23
32
Dbms unit 3 long answers
Database Management Systems100% (4)
10
Brown Girls
impact15
P.E.S. Institute of Technology and Management
Discover more
17
31
32
46
DBMS Notes
Database Management Systems94% (16)
41
12
DBMS - Unit 5 Notes - abcdefghijklmnopqrstuvwxyz
Database Management Systems100% (5)
23
32
10
Company
About us
Ask AI
Studocu World University Ranking 2023
E-Learning Statistics
Doing Good
Academic Integrity
Jobs
Blog
Dutch Website
Contact & Help
F.A.Q.
Contact
Newsroom
Legal
Terms
Privacy policy
Cookie Settings
Cookie Statement
English (IN)
India
out of 15
v
Experiment 2.
Creating and Managing Branches:
Create a new branch named "feature-branch." Switch to the "master" branch. Merge
the "feature-branch" into "master."
Solution:
To create a new branch named "feature-branch," switch to the "master" branch,
and merge
the "feature-branch" into "master" in Git, follow these steps:
$ git add .
$ git commit -m "Your commit message for feature-branch"
Replace "Your commit message for feature-branch" with a descriptive commit
message for
the changes you made in the "feature-branch."
1. Switch back to the "master" branch: