Git Commands

Git clone command

This command is used to make a copy of a repository from an existing URL. If I want a local copy of my repository from GitHub, this command allows creating a local copy of that repository on your local directory from the repository URL.

Syntax

$ git clone URL  


Git add command

This command is used to add one or more files to staging (Index) area.

Syntax

To add one file

$ git add Filename

 

To add more than one file

 

$ git add*  

 

Git commit command

Commit command is used in two scenarios. They are as follows.

Git commit -m

This command changes the head. It records or snapshots the file permanently in the version history with a message.

Syntax

$ git commit -m " Commit Message"  

 

Git commit -a

 

This command commits any files added in the repository with git add and also commits any files you've changed since then.

Syntax

$ git commit -a  


Git status command

The status command is used to display the state of the working directory and the staging area. It allows you to see which changes have been staged, which haven't, and which files aren’t being tracked by Git. It does not show you any information about the committed project history. For this, you need to use the git log. It also lists the files that you've changed and those you still need to add or commit.

 

Syntax

 

$ git status


Git push Command

It is used to upload local repository content to a remote repository. Pushing is an act of transfer commits from your local repository to a remote repo. It's the complement to git fetch, but whereas fetching imports commits to local branches on comparatively pushing exports commits to remote branches. Remote branches are configured by using the git remote command. Pushing is capable of overwriting changes, and caution should be taken when pushing.

Git push command can be used as follows.

Git push origin master

This command sends the changes made on the master branch, to your remote repository.

Syntax

$ git push [variable name] master  

Git pull command

Pull command is used to receive data from GitHub. It fetches and merges changes on the remote server to your working directory.

Syntax

$ git pull URL  

 

Git Branch Command

This command lists all the branches available in the repository.

Syntax

$ git branch

Git log Command

This command is used to check the commit history.

Syntax

$ git log  



Commands in short :

Example :

git checkout gsa_automation_prod - This will switch to gsa_automation_prod branch

git status - Used to check the status (which branch currently owning)

git pull origin gsa_automation_prod  - This will pull the code which is there in git with gsa_automation_prod

-------------------------------------------------------------------

COPY the files required to be added into the folder

-------------------------------------------------------------------

git add . - This will add all the folders in the folder

git status - Afer adding status check will show the newly added files in RED

git commit -m "Load Verification & File Transfer Project" - Commits the files

git push origin gsa_automation_prod - Push the code to gsa_automation_prod

 

Comments

Popular posts from this blog

Why to do a POC (Proof Of Concept)