Lec. 3.1
Lec. 3.1
PROGRAMMERS </> C
C++
What is Git?
01.
What is C LANG.
Git?
GIT
Git is a free and open-source distributed version control system
designed to handle everything from small to very large projects with
speed and efficiency.
1. Configurations
2. Starting a repository
3. Staging files
4. Committing to a repository
5. Pulling and pushing from and to repositories
6. Branching
01 $ git config --global user.name "FirstName LastName"
$ git config --global user.email "your-email-address"
$ git config --list
Configurations
commands
Configurations commands
git config --global user.name "FirstName LastName"
This command is used to set the author name that will be used for all commits on
the current system.
This information is associated with your Git commits and is helpful for identifying
who made a particular commit.
--global: This flag indicates that the configuration should be set globally, affecting
all repositories on your system.
If you omit --global, the configuration will be specific to the current repository.
Configurations commands
git config --global user.email "your-email-address"
This command is used to set the email address associated with your Git commits.
--global: This flag indicates that the configuration should be set globally, affecting
all repositories on your system.
If you omit --global, the configuration will be specific to the current repository.
Configurations commands
git config --list
This command is used to display the configuration settings for Git on your
system.
When you run this command, Git will output a list of all the configuration settings
along with their current values.
02 $ git init
$ git status
Starting Repository
commands
Starting Repository commands
git init
This command is used to initialize a new Git repository. It sets up all the necessary
files and data structures required for version control using Git.
Here's a basic breakdown of what git init does:
Creates a Hidden Subfolder: It creates a hidden subfolder within the existing directory that houses the internal data structure required for version
control. This subfolder is usually named .git.
Initializes Configuration Files: Git config files are created within the .git subfolder. These files will store your configuration options and
project-specific settings.
Sets Up the Initial Branches: The command sets up the default branches (usually master) and initializes them to be empty.
Ready for Commits: After running git init, your project is ready to start tracking changes. You can now use other Git commands, like git add to
stage files, and git commit to save a snapshot of the project.
Starting Repository commands
git status
Changes to be Committed: It shows a list of changes that are staged and ready to be committed. These are changes that you have added to the
staging area using git add.
Changes not staged for Commit: It shows modifications in your working directory that haven't yet been staged. These are changes that you
made to files but haven't yet added to the staging area.
Branch Information: If you're on a specific branch, git status will indicate which branch you are on and whether your branch is ahead, behind, or
has diverged from a remote branch.
03 $ git add <file-name>
$ git add <file-name> <another-file-name>
$ git add .
$ git add --all
Staging files
$ git add -A
$ git rm --cached <file-name>
$ git reset <file-name>
commands
Staging files commands
git add <file-name>
This command is used to stage changes in a specific file for the next commit.
It tells Git that you want to include updates to that file in the next snapshot of the
repository.
Staging files commands
git add <file-name> <another-file-name>
This command is used to stage changes in multiple specific files for the next
commit.
It allows you to add more than one file to the staging area in a single command.
Staging files commands
git add .
This command is used to stage all changes in the current directory and its
subdirectories for the next commit.
This command is a shorthand way to add all modifications and new files to the
staging area.
Staging files commands
git add --all
This command is another way to stage all changes in the working directory for
the next commit.
It is equivalent to git add --all and stages all modifications, deletions, and
untracked files.
This command is used to untrack a file in Git without deleting it from your
working directory.
This command removes a file from the staging area (index) but keeps it in your
local file system.
Staging files commands
git reset <file-name>
It removes the changes from the staging area while keeping the modifications in
your working directory unchanged.
04 $ git commit -m "Add three files"
$ git commit --amend -m < enter your message>
Committing repository
commands
Committing repository commands
git commit -m "Add msg"
This command is used to save the staged changes in your Git repository with a
commit message.
It creates a snapshot of the changes that you've previously staged using git add.
Committing repository commands
git commit --amend -m <updated commit message>
This means you can make changes to the last commit message or add changes
that you forgot to include in the last commit.
Here's how the command works:
git commit --amend: This command allows you to modify the last commit. It opens the default text editor for you to modify the commit message.
If you only want to modify the commit message without changing the content, you can skip the -m flag.
-m <enter your message>: This option is used to provide a new commit message directly on the command line without opening the text editor.
Replace <enter your message> with the new commit message.
05 $ git remote add origin <link>
$ git push -u origin master
$ git clone <clone>
$ git pull
This command is used to add a remote repository named "origin" to your local
Git repository.
The term "origin" is a conventionally used name, but you could choose a different
name if you prefer.
Here's how the command works:
git remote add: This command is used to add a new remote repository.
origin: This is the name assigned to the remote repository. "Origin" is a common convention, but you could choose another name if you prefer.
<link>: Replace <link> with the URL of the remote repository. This is the link to the repository you want to connect to.
Pulling and pushing commands
git push -u origin master
This command is used to push the local changes from the "master" branch to the
remote repository named "origin."
This command is often used for the initial push to set up a tracking relationship
between the local and remote branches.
Pulling and pushing commands
git clone <repository URL>
This command is used to create a copy of a remote Git repository on your local
machine.
This command clones a repository, creating a local working copy with the entire
history of the project, including all branches.
Pulling and pushing commands
git pull
This command is used to fetch changes from a remote repository and integrate
them into the current working branch.
git fetch: This command retrieves the changes from the remote repository,
including new branches or changes to existing branches.
git merge: After fetching changes, git pull automatically merges those changes into
the current branch.
06 $ git branch
$ git branch <branch-name>
$ git checkout <branch-name>
$ git merge <branch-name>
Branching
$ git checkout -b <branch-name>
commands
Branching commands
git branch
When used without any additional arguments, this command lists all the branches
in the repository.
This command creates a new branch with the specified name but does not switch
to that branch; you remain on the current branch.
Branching commands
git checkout <branch-name>
It allows you to navigate between branches and work on the code associated with
a specific branch.
Branching commands
git merge <branch-name>
This command is used to integrate changes from one branch into another.
This command combines the changes made on a specified branch (called the
source branch) into the current branch (called the target branch).
Branching commands
git checkout -b <branch-name>
02.
C LANG.
What is
GitHub?
GitHub