Git Commands

Posted on Posted in Cheat Sheets, Topics

Knowledge of version control systems are a mandatory skill set for developers.

Git is among the most popular.

It is a is a free and open source distributed version control system designed to handle any size software development project, however, it can also keep track of changes to any type of files.

If you want to create your own remote Git repositories you might want to check out https://github.com/ and https://bitbucket.org/. Both are great services and with bitbucket, you can also create private repositories.

So that being said I thought it might be a good idea to keep a list of most common commands (obviously a subjective POV).

 

Git commands

Working tree status:

 

Stage changes all for commit:

 

Commit changes to the local repository:

 

Push changes to the remote repository:

 

Updates local repository with branches and/or tags along with the objects necessary to complete their histories:  

 

Fetch and integrate with another repository or a local branch: 

 

List branches:

 

Create a branch in local repository:

 

Create a branch in the local repository and switch to the new branch:

 

Push branch from the local repository to the remote repository:

 

Show remote branches

 

Delete local branch

 

Delete remote branch:

 

Rename local branch:

 

Rename remote branch:

1. Rename local branch: 

2. Delete remote branch: 

3. Push the new branch, set local branch to track the new remote:

 

Switch branch:

 

Fetch remote branch

 

Pull remote branch

 

List tags:

 

Create annotated tag:

 

Remove file from repository and file system:

 

Remove file only from the repository, but not file system:

 

How to merge a branch into another branch:

1. Save your changes:

or

2. Check out the branch you want to be merged into your current branch

3. Update branch, if needed:

4. Go back to your original branch:

5. Merge:

 

Save your local modifications and reverts the working directory to match the HEAD commit:

 

Remove a single stashed state from the stash list and apply it on top of the current working tree state:

 

 

To be continued…

Spread the knowledge

Leave a Reply

Your email address will not be published. Required fields are marked *