DEV Community

Alex Reis
Alex Reis

Posted on

Git: Commands beginners don't know

Git is a Version Control System designed to handle everything from small to very large projects with speed and efficiency. You should already the basics commands: init, add, commit and push. But I want to introduce you to some basic commands that can help you a lot, so let's go.

git merge

Incorporates changes from the commits of another branch into the current branch.

$ git checkout <branch that will receive changes>
$ git merge <branch with changes>
Enter fullscreen mode Exit fullscreen mode

git rebase

Reapply commits on top of another branch.

$ gut checkout <branch that will receive changes>
$ git rebase <branch with changes>
Enter fullscreen mode Exit fullscreen mode

git stash

Use git stash when you want to record the current state of the working directory and the index, but not commit this modifications.

$ git stash
Enter fullscreen mode Exit fullscreen mode

Can be list the modifications stashes:

$ git stash list
Enter fullscreen mode Exit fullscreen mode

Restored:

$ git stash apply
Enter fullscreen mode Exit fullscreen mode

Apply specific stash:

$ git stash apply stash@{2}
Enter fullscreen mode Exit fullscreen mode

git cherry pick

Apply the changes introduced by some existing commits.

$ git cherry-pick <commit hash>
Enter fullscreen mode Exit fullscreen mode

git commit --amend

Modify the latest commit:

$ git commit --amend
Enter fullscreen mode Exit fullscreen mode

If you commit and forgot to stage the changes in a file you wanted to add to this commit:

$ git commit -m 'Initial commit'
$ git add forgotten_file
$ git commit --amend
Enter fullscreen mode Exit fullscreen mode

Conclusion

Eu hope this article has been helpful for your learning. Look the 'Reference' to learn more about git.

Reference

Git Documentation

Top comments (0)