Git&Hub
1. What is the difference between pushing and pulling..?
Ans:
Push means when you have to save your code to git. Push command refers to the pushing of the local repository content to a remote repository. If you're the only one working on a repository & Pull - pulling grabs any changes from the GitHub repository and merges them into your local repository.
Pull means when you want to retrieve existing code from the git. Pull command is used to fetch and merge changes from the remote repository to the local repository. The pull command is a combination of two commands, git fetch command followed by git merge command.
2. How to initialize a new git repository[ Describe all the steps ]..?
Ans:
Install Git for your OS. After installing Git, create a GitHub account.
Now go to your terminal and introduce yourself to Git! To set your username for every repository on your computer, type
git config — global user.name “<your_name_here>”
git config — global user.email “<your_email@email.com>”
After that, you are ready to create your first repository. Go to GitHub. Click on the (+) sign in the upper right corner and select “New repository”.
Type your repository name and click on “Create repository”.
$ git init
If you would then like to put your current project files under version control, you can make your first commit:
# Add all files to the staging area (= tell Git to include them in the next commit)
$ git add .
# Wrap these changes in a commit and save them to the local Git repositormit"
$ git commit -m "First commit"
3. What is the use of git clone and how to use it?
Ans: git clone is primarily used to point to an existing repo and make a clone or copy of that repo at in a new directory, at another location. It takes the entire online repository and makes an exact copy of it on your local machine.
Commands to clone a Repo from GitHub:
git clone https://github.com/username/myrepo.git
cd myrepo — your repo name
4. How to ignore some files/folders from pushing?
Ans:
Recommended by LinkedIn
You can use .gitignore to select what you don't want to push it up to git server.
Just put .gitignore to your root folder and add ./assets/* to this file.
5. What do you mean by Branch?
Ans:
You can think of your git repo as a tree. The trunk of the tree, the software that goes live, is called the Master Branch. That’s the one that goes live. The branches of that tree are, well, called branches. These are separate instances of the code that offshoots from the main codebase.
- Which branch should be used to keep deployment-ready code?
Ans:
The Central branch is always in a deployment-ready state. In other words, the main branch for the project should only contain tested and quality work, and should never be broken.
- Create a new branch called development from the main branch.
Ans:
$ git branch <branch-name>
$ git checkout <branch-name>
$ git checkout -b <branch-name>
$ git push -u <remote> <branch-name>
- Checkout one more branch deployment from the previous branch.
Ans:
@{-1} is a way to refer to the last branch you were on. This is
accepted not only where an object name is expected, but anywhere a branch name is expected and acts as if you typed the branch name.
git checkout -
which can be also written as:
git checkout @{-1}
- Push different data into both branches.
Ans:
git checkout -b B
git add . //or specific file(s)
git commit -m "commit_message"
git push origin B
- Merge data from both branches to the main branch.
Ans: Merging your branch into master is the most common way to do this. Git creates a new commit message(-m) that is referred to as a merge commit that results from combining the changes from your feature branch and master from the point where the two branches diverged.
git checkout main
git merge feature