Table of contents
- Stages of git/workflow
- Importance/Advantages of Git
- What is Branch
- Difference between Main Branch and Master Branch
- Create a new repository on GitHub and clone it to your local machine.
- Make some changes to a file in the repository and commit them to the repository using Git.
- Push the changes back to the repository on GitHub
- What is the difference between local & remote repositories? How to connect locally to the remote?
- How do you create a new repository on GitHub?
Stages of git/workflow
Repository
A repository is a place where you have all your codes or kind of folder on the server.
It is a kind of folder related to one product.
ChanIges are Personal to that Particular Repository.
Server
It stores all Repositories.
It contains metadata also.
Working directory
Where you see files physically and do modifications.
At a time, you can work on Particular Branch.
Note
In other CVCS, developer generally makes modifications and commit their changes directly to the Repository but git uses a different strategy. Git does not track each and every modified file. Whenever you do commit an Operation git looks for the files present in the staging area. Only those files present in the staging area are considered for commit and not all the modified files.
Commit
Store changes in the repository, and we will get one Commit-ID.
It is 40 alpha-numeric characters.
It uses the SHA-1 checksum concept.
Even if we change one dot, Commit-ID will get changed.
It helps us to track the changes.
Commit is also named SHA-1 hash. Commit-ID/ Version-ID/ Version
Reference to identify each change.
To identify who changed the file.
Tags
Tags assign a meaningful name with a specific version in the repository. Once a tag is created for a particular save, even if you create a new commit, it will not be updated.
Snapshots
Represent some data of a particular time.
It is always incremental i.e. It stores the changes (appended data) only not the entire copy.
Push
Push operation copies changes from local Repository instances to a Remote or Central Repo. This is used to store the changes permanently in the git Repository.
Pull
Pull operation copies the changes from a Remote Repository to a local machine. The pull operation is used for synchronization between two repo.
Importance/Advantages of Git
Free and open source.
Fast and Small:- As most of the operations are performed locally, therefore it is fast.
No need for powerful hardware.
Security:- git uses a common cryptographic hash function called secure hash function (SHA-1) to name and identify objects within its database.
Easier Branch:- If we create a new branch it will copy all codes to the new branch.
What is Branch
The diagram above visualizes a Repository with two isolated lines of development, one for little features, and one for longer-running features. By developing them as Branches, it's not only possible to work on both of them in parallel, but it also keeps the Main Master Branch free from Error.
Each task has one separate Branch.
After done with the code, Merge other Branches with the master.
This concept is useful for parallel development.
You can create any no of branches.
Changes are personal to that particular Branch.
The default Branch is 'Master'
Files Created in the workspace will be visible in any of the branch workspaces until you commit. Once you commit, then that file belongs to that particular Branch.
When creating a new branch, data from the existing Branch is copied to the new Branch.
Difference between Main Branch and Master Branch
main or master is the default branch when you create a repository. A branch in Git is used to keep your changes. Each repository can have one or more branches. The default branch of any GitHub repository is the main and for local repositories, it's the master.
Create a new repository on GitHub and clone it to your local machine.
Log in to your GitHub account and click on the New button to create a new repository. Enter a name for your repository and choose whether the repository should be public or private.
- Once the repository is created, copy the repository's URL to your clipboard.
Open up a terminal or command prompt on your local machine and navigate to the directory where you want to clone the repository.
Now clone the repository by using this command.
git clone
https://github.com/YOUR-USERNAME/YOUR-REPOSITORY
Make some changes to a file in the repository and commit them to the repository using Git.
Create a test file using the vim editor and check the status using this command, it'll show an untracked file.
git status
- Add the test file to the staged area and check the status, now it's tracked.
git add .
Orgit add FILENAME
- Add the test file to the staged area and check the status, now it's tracked.
- Commit the staged file to the git using this command.
git commit -m "Your Message"
Push the changes back to the repository on GitHub
The git push command is used to upload local repository content to a remote repository.
git push <remote> <branch>
What is the difference between local & remote repositories? How to connect locally to the remote?
Git local repository is the one on which we will make local changes, typically this local repository is on our computer. Git remote repositories are hosted on a server that is accessible to all team members.
Navigate to the local repository on your system and use this command to connect locally to the remote.git remote add origin <remote_repo_URL> git push --all origin
If you want to set all of your branches to automatically use this remote repository when you use git pull
, add --set-upstream
to the push:git push --all --set-upstream origin
How do you create a new repository on GitHub?
Go to github.com and log in to your account.
In the upper-right corner, Click the "+" and select New repository from the dropdown.
Enter a name for your repository.
Add a description if you like (optional)
Choose whether you want the repository to be public or private.
Add a README file.
Click the “Create repository” button.
See Part-3 ✌️😁
Thanks for reading!!