Git help cheat sheet

Git help cheat sheet

While attending the Write the Docs conference, I learned that several folks are trying to learn Git. After you get a basic understanding of Git (see Running basic Git commands and Migrating to Docs-as-Code for a diagram), what do you do when you make a mistake?

This article provides tips to resolve common errors. I will add to this as I encounter other issues (as I jotted these down just hours after the conference ended).

Please add your tips in the comments or send me a message and I will add them.

Also, if you know a better way to fix something or if I made a mistake, please let me know! I am learning just like everyone else.


Delete a local branch

git branch -d <branch>        


Delete a remote branch

List all the branches:

git branch -a        

You can press Enter to see more branches. Then, press q to exit the list.

Delete the branch:

git push origin -d <branch>        


Move a commit from master to a new branch

git branch <new branch name

git reset HEAD~ --hard

git checkout <new-branch-name>>        


Undo a commit

Get the hash for the commit. The hash is the SHA-1 hash that identifies the commit.

To do this:

git log        
No alt text provided for this image

The result will look something like the following:

Revert the commit:

git revert --no-commit <hash>
git commit -m "revert <hash>"
git push        

Note: You can run multiple git revert --no-commit <hash> commands in a row.


Move commits from one branch to another

You can use the cherry-pick command to apply commits from one branch to another. This can be tricky, but it can also be very useful.

Get the hashes for the commits that you want to cherry-pick. A hash is the SHA-1 hash that identifies the commits.

To do this:

git checkout <branch that has the commit to cherry pick>
git log
        

The following is an example of a single commit:

No alt text provided for this image
git checkout <main branch - this can be main, develop - depending on your environment>
git pull
git checkout -b <new branch>
git cherry-pick <hash 1>
git cherry-pick <hash 2>
git log 
git push        
Make sure you apply the cherry-picked commits in the order in which they were committed.

For example, if you the earliest commit in git log is hash ae056b, then df045c, then ce135d, you would list them in this order:

git cherry-pick ae056b
git cherry-pick df045c
git cherry-pick ce135d        

要查看或添加评论,请登录

Tara N. English-Sweeney的更多文章

  • Essential Features Every CCMS Should Have for Content Authors

    Essential Features Every CCMS Should Have for Content Authors

    If you’re a Component Content Management System (CCMS) vendor, the features you build directly affect how efficiently…

  • Behind the Scenes of Our Content Migration

    Behind the Scenes of Our Content Migration

    Migrating content is never easy, but it’s always transformative. Our Technical Writing team is currently transitioning…

    14 条评论
  • Transforming Docs with GPT

    Transforming Docs with GPT

    To prepare for an upcoming migration to a content management system (CMS), our team is converting feature-based product…

    15 条评论
  • CMS Migration Project: Human versus ChatGPT

    CMS Migration Project: Human versus ChatGPT

    If you're a Technical Writer migrating to a new Component Content Management System, you know it's a massive…

    7 条评论
  • How to Create a Style Guide

    How to Create a Style Guide

    Style guides are an important part of a documentation team's toolset. They ensure your team and organization write with…

  • How to plan user research

    How to plan user research

    We must reorganize our documentation. Our team of four is acutely aware of this.

    2 条评论
  • How to be a great Documentation Engineer

    How to be a great Documentation Engineer

    Writing technical documentation is a job that many folks can do fairly well. However, if you want to be the best, then…

    6 条评论
  • Automate Style Checks

    Automate Style Checks

    Vale is a tool that brings code-like linting to text. You can run the tool on a file and it shows validation errors…

  • Looking for work (new vs. experienced writer)

    Looking for work (new vs. experienced writer)

    Content strategist Technical writer UX writer Information developer Over time, the title evolves. The role evolves.

    1 条评论
  • Making an impact: Changing the way Product and Engineering work with the Writing team

    Making an impact: Changing the way Product and Engineering work with the Writing team

    How great is it to dive headfirst into a difficult project, take the reigns, and make things better? Do you find it…

    1 条评论

社区洞察

其他会员也浏览了