Git Cheat Sheet

Basic Git Commands:

1. Initialize a Repository:

git init

2. Clone a Repository:

git clone <repository_url>

3. Check Status:

git status

4. Add Files to Staging Area:

git add <file_name>

5. Commit Changes:

git commit -m "Your commit message"

6. Push Changes to Remote Repository:

git push origin <branch_name>

7. Pull Changes from Remote Repository:

git pull origin <branch_name>

8. Create a New Branch:

git branch <branch_name>

9. Switch to a Branch:

git checkout <branch_name>

10. Merge Branches:

git merge <branch_name>

11. View Commit History:

git log

12. Revert Changes:

git revert <commit_hash>

13. Stash Changes:

git stash

14. Apply Stashed Changes:

git stash apply

15. Delete a Branch:

git branch -d <branch_name>

Advanced Git Commands:

1. Rebase:

git rebase <branch_name>

2. Cherry-Pick:

git cherry-pick <commit_hash>

3. Reset to a Previous Commit:

git reset --hard <commit_hash>

4. Amend the Last Commit:

git commit --amend

5. Interactive Rebase:

git rebase -i <commit_hash>

What Undercode Say:

Git is an essential tool for version control, widely used in software development to track changes, collaborate with others, and manage code efficiently. The commands listed above cover the basics and some advanced functionalities of Git, enabling developers to handle repositories with ease.

For those new to Git, starting with `git init` and `git clone` is crucial to set up your local repository. Regularly using `git status` helps in understanding the current state of your working directory. Committing changes with `git commit` and pushing them to a remote repository with `git push` ensures that your work is saved and shared with your team.

Branching and merging are powerful features that allow multiple developers to work on different features simultaneously without interfering with each other’s work. Commands like git branch, git checkout, and `git merge` are fundamental for managing branches.

Advanced users can leverage `git rebase` to maintain a clean project history, `git cherry-pick` to apply specific commits, and `git reset` to undo changes. Stashing changes with `git stash` is useful when you need to switch contexts without committing incomplete work.

In conclusion, mastering Git commands enhances productivity and collaboration in software development. Practice these commands regularly to become proficient in version control. For further reading, refer to the official Git documentation: Git Documentation.

Related Commands:

  • Linux:
    ls -la
    
    chmod 755 <file_name>
    
    grep "pattern" <file_name>
    

  • Windows:
    [cmd]
    dir
    [/cmd]
    [cmd]
    icacls /grant :F
    [/cmd]
    [cmd]
    findstr “pattern”
    [/cmd]

By integrating these commands into your workflow, you can streamline your development process and ensure efficient project management.

References:

Hackers Feeds, Undercode AIFeatured Image

Scroll to Top