0% found this document useful (0 votes)
34 views2 pages

Git Cheat Sheet

Git cheet sheet

Uploaded by

amarmethre.1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views2 pages

Git Cheat Sheet

Git cheet sheet

Uploaded by

amarmethre.1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Git Cheat Sheet with Example

This cheat sheet provides common Git commands with an example to help you understand
the basics.

Scenario: Managing a Project with Git


Suppose you're working on a project called 'MyProject' and want to track changes using Git.
Here's a step-by-step cheat sheet for common Git commands.

1. Setting up Git
1. Configure your Git

1. Run the following commands to set up your Git username and email globally:

git config --global user.name "Your Name"


git config --global user.email "your.email@example.com"

2. Initialize a Repository
2. Navigate to your project folder and initialize Git tracking:

cd MyProject
git init

3. Working with Files


3. 1. Check the status of your files:

git status

4. 2. Add a new or modified file to staging:

git add filename.txt

5. 3. Commit your changes with a message:

git commit -m "Added a new feature"

4. Working with Branches


6. 1. Create a new branch:

git branch feature-branch

7. 2. Switch to the new branch:

git checkout feature-branch

8. 3. Merge the branch back into the main branch:


git checkout main
git merge feature-branch

5. Viewing History
9. 1. View commit history:

git log

10. 2. View changes in files:

git diff

6. Working with Remote Repositories


11. 1. Add a remote repository:

git remote add origin https://github.com/username/MyProject.git

12. 2. Push changes to the remote repository:

git push -u origin main

7. Useful Shortcuts
13. 1. Stage all changes and commit with one command:

git commit -am "Updated files"

14. 2. Discard all local changes:

git reset --hard

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy