Article on GIT & GITHUB
Difference between Git and Github :-
Git: Git is a distributed version control system for tracking changes in source code during software development. It is designed for coordinating work among programmers, but it can be used to track changes in any set of files. Its goals include speed, data integrity, and support for distributed, non-linear workflows.
GitHub: GitHub is a web-based Git repository hosting service, which offers all of the distributed revision control and source code management (SCM) functionality of Git as well as adding its own features.
Q1. What is the difference between pushing and pulling?
Pushing to a remote : send some commits you have to a another git repo. The git repo is considered as "remote", but it can be a repo in another folder of your hard drive.
Pulling from a remote : get some commits from a remote repo and merge them in your current HEAD (your current checkout of your repo)
Q2. How to initialize a new git repository (describe all the steps)?
- Create a directory to store the project.
- Go into the new directory.
- Enter the command "git init".
- Write some code.
- Enter "git add" to add the files.
- Lastly, enter "git commit" to commit all the files.
Q3. What is the use of a git clone and how to use it?
The git clone command is used to create a copy of a specific repository or branch within a repository.
Git is a distributed version control system. Maximize the advantages of a full repository on your own machine by cloning.
Common usages and options for git clone
- git clone [url]: Clone (download) a repository that already exists on GitHub, including all of the files, branches, and commits.
- git clone --mirror: Clone a repository but without the ability to edit any of the files. This includes the refs, or branches. You may want to use this if you are trying to create a secondary copy of a repository on a separate remote and you want to match all of the branches. This may occur during configuration using a new remote for your Git hosting, or when using Git during automated testing.
- git clone --single-branch: Clone only a single branch
- git clone --sparse: Instead of populating the working directory with all of the files in the current commit recursively, only populate the files present in the root directory. This could help with performance when cloning large repositories with many directories and sub-directories.
Q4. How to ignore some files/folders from pushing?
Create a .gitignore file in your Git repo to prevent Git from staging unwanted files. Share .gitignore in the default branch in your repo. You and your team can update the file to change which types of files to ignore.
If you're using Windows it will not let you create a file without a filename in Windows Explorer. It will give you the error "You must type a file name" if you try to rename a text file as .gitignore
To get around this I used the following steps
- Create the text file gitignore.txt
- Open it in a text editor and add your rules, then save and close
- Hold SHIFT, right click the folder you're in, then select Open command window here
Then rename the file in the command line, with ren gitignore.txt .gitignore
Q5. What do you mean by Branch?
Branches allow you to develop features, fix bugs, or safely experiment with new ideas in a contained area of your repository.
You always create a branch from an existing branch. Typically, you might create a new branch from the default branch of your repository. You can then work on this new branch in isolation from changes that other people are making to the repository. A branch you create to build a feature is commonly referred to as a feature branch or topic branch.
You can also use a branch to publish a GitHub Pages site.
You must have write access to a repository to create a branch, open a pull request, or delete and restore branches in a pull request.
When you create a repository with content on GitHub, GitHub creates the repository with a single branch. This first branch in the repository is the default branch. The default branch is the branch that GitHub displays when anyone visits your repository. The default branch is also the initial branch that Git checks out locally when someone clones the repository. Unless you specify a different branch, the default branch in a repository is the base branch for new pull requests and code commits.
By default, GitHub names the default branch main in any new repository.
(a) Which branch should be used to keep deployment-ready code?
Production Branch (Develop)
(b) Create a new branch called development from the main branch.
git checkout -b development (Now, we are in the master branch and created development branch)
(c) Check out one more branch deployment from the previous branch.
git checkout development (checkout in development branch from master branch)
git checkout -b deployment (Now, we are in the development branch and created deployment branch)
(d) Push different data into both branches.
git push (Push data in development branch)
git checkout deployment (checkout in deployment branch from a development branch)
git push (Push data in deployment branch)
(e) Merge data from both branches to the main branch.
git checkout master (checkout in master branch from deployment branch)
git merge development (Merge development branch with master branch )