Git CheetSheet

Git - a version control system

Jan 6, 2024 - 19:16
 0  29
Git CheetSheet
Git

Introduction of Git 

GitHub has become an indispensable tool for developers, enabling collaboration, version control, and streamlined project management. Whether you're a seasoned developer or just starting, understanding the ins and outs of GitHub can significantly enhance your workflow. In this blog post, we'll explore key GitHub features, best practices, and tips to help you make the most of this powerful platform. 

Getting Started with GitHub: 

Sign up for a GitHub account if you haven't already. 

Create your first repository. 

Understand the basic structure of a repository: branches, commits, and pull requests. 

Version Control with Git: 

Invite collaborators to your repository. 

Forking vs. Branching: When to use each. 

Collaborative workflows using pull requests. 

Contributing to open-source projects on GitHub. 

Managing community interactions and discussions. 

Code of Conduct and best practices for maintaining a healthy open-source project. 

. Initializing a Repository 

Commands for Git actions 

git init 

Initializes a new Git repository in the current directory. 

git clone <repository-url> 

Creates a copy of a remote repository on your local machine. 

2. Basic Snapshotting 

git add <file> 

Adds changes in the working directory to the staging area. 

git status 

Displays the status of changes as untracked, modified, or staged. 

git diff 

Shows the differences between the working directory and the staging area. 

git commit -m "Commit message" 

Records changes from the staging area in the repository. 

3. Branching and Merging 

git branch 

Lists all local branches in the repository. 

git branch <branch-name> 

Creates a new branch. 

git checkout <branch-name> 

Switches to a specified branch. 

git merge <branch-name> 

Merges changes from one branch into the current branch. 

git pull 

Fetches changes from a remote repository and merges them into the current branch. 

git push 

Pushes changes to a remote repository. 

4. Undoing Changes 

git reset <file> 

Unstages changes from the staging area. 

git revert <commit> 

Creates a new commit that undoes changes made in a previous commit. 

git reset --hard <commit> 

Discards changes in the working directory and staging area to a specific commit. 

5. Inspecting and Comparing Changes 

git log 

Displays a log of all commits in the repository. 

git show <commit> 

Shows information about a specific commit. 

6. Remote Repositories 

git remote -v 

Lists all remote repositories. 

git remote add <name> <url> 

Adds a new remote repository. 

git fetch <remote> 

Fetches changes from a remote repository. 

7. Tagging 

git tag 

Lists all tags in the repository. 

git tag -a <tag-name> -m "Tag message" 

Creates an annotated tag. 

8. Stashing 

git stash 

Stashes changes in the working directory for later use. 

git stash pop 

Applies the most recent stash and removes it from the stash list. 

9. Configuration 

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

Configures the author's name to be used with your commits. 

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

Configures the email to be used with your commits. 

git config --list 

Lists all Git configuration settings. 

 

 

What's Your Reaction?

like

dislike

love

funny

angry

sad

wow

vinita kushwah Front end developer