GIT Tips/ Interview Questions & Answers: Here Are Some Basic Git Commands. Hope This Will Help You
GIT Tips/ Interview Questions & Answers: Here Are Some Basic Git Commands. Hope This Will Help You
Here are some basic Git Commands. Hope this will help you.
01) How do you start Git and what is the process called?
A) $ git init
The process is called initializing a git repository
02) How do you determine the current state of the project?
A) $ git status
03) How Can I Move all your changes since your last commit to the staging area.
A) $ git add .
04) How to Store the saved changes in the repository and add a message "first commit".
A) $ git commit -m "first commit"
05) Show a list of all the commits that have been made.
A) $ git log or $ git g
06) How do you put your local repository (repo) on the GitHub server?
A) a. create a new repository in github
b. get the SSH key (SSH stands for secure shell)
c. $ git remote add origin [SSH key - something like [email protected]…]
d. $ git push -u origin master
07) How to take a git project from GitHub to your local machine to work on it.
A) $ git pull origin master
Or, if you are taking a project that is not already on your local machine, use $ git clone.
08) What is the purpose of working off multiple branches.
A) You can create a separate branch when you are developing a feature, etc. and can commit to this
branch separately. When the feature branch is working properly, you can merge it with the master
branch.
09) Write the command to create a branch called working
A) $ git checkout -b working
10) How to list all of the branches.
A) $ git branch
11)How to switch to the working branch
A) $ git checkout working
12) How to merge the changes that were made in the working branch with the master branch.
A) $ git checkout master
$ git merge working
13) How to delete the working branch
A) $ git branch -d working
14) What is the command to Put everything up on the remote repository.
A) $ git push
15) Pull a branch from a remote repository and create the branch locally.
A) git checkout -b fix_stuff origin/fix_stuff
16) How to Make a directory called git_test?
A) $ mkdir git_test
17) How can I Change to git_test directory ?
A) $ cd git_test
18) How to make sure that you are in the right directory?
A) $ pwd
/Users/username/Desktop/git_test
19) How Can I Initialize and empty git repository?
A) $ git init
20) How to Create a text file called form.txt
A) $ touch form.txt
21)Open readme.txt file with your text editor and add two lines of text:
This is the first line of text
This is the second line of text
Check the git status
A) $ git status
Notice that you are on the master branch and that changes have not been committed yet
22) How to Add the files to be committed?
A) $ git add new.txt
23) What is the command to Make your first commit?
A) $ git commit -m “first commit”
24) How to Add the changes and make a second commit?
A) $ git add .
$ git commit -m “Second commit”
25) How Can I Create a new branch called temp?
A) $ git checkout -b temp
26) How Can I check my Branch Status?
A) $ git branch or $ git b
27) Run a command to show the commits that have been made to the temp branch.
A) $ git log
28) How Can I Switch to the other branch?
A) $ git checkout other branch.
29) Add a line to the some.txt file and then throw out all changes since the last commit.
A) $ git reset --hard