DEV Community

Cover image for Git/Github workflow and Tips
Ahmet Akinsel
Ahmet Akinsel

Posted on • Updated on


Git/Github workflow and Tips

This post is written to guide and help the junior software developers. I want to share the useful tips and information I learned about Git/Github during my first 3 months of experience.

  • Before starting to work, always pull the latest from the master.
  • Always work on a separate branch.
  • Prevent direct commits, don't git push straight to the master.
  • All commits should be pushed to the master through "pull requests".
  • Pay attention to branch naming conventions.
  • Write meaningful commit messages. You can use “verb + context” pattern when commenting on descriptions in PRs. e.g: fixed card width.
  • Make sure to write a PR description about the work you have done or the problems you encounter.
  • Track the PRs that you created. Don’t forget to check all the changes requested and pipelines. Make sure all checks have passed.
  • Avoid committing large files. Optimum commit is between 300-500 lines of code.
  • Delete outdated branches.
  • Always check your github notifications.

Some useful git commands:

  • git diff (shows unstaged changes since last commit)
  • git reset (undoes git add before commit)
  • git log (shows a list of all the commits made to a repository)
  • git push –no-verify (uploads local repository content to a remote repository without verification)
  • git status (gives all the necessary information about the current branch)
  • git branch (viewing branches)
  • git branch -r (shows your remote branches)
  • git checkout -b <branch-name> (creates a new branch)
  • git checkout - (switches back to previous branch)
  • git checkout -- . (cancels all changes for the current branch you're working on)
  • git reset --hard origin/master (this commands  basically  forgets everything on your current local branch and makes it exactly the same as the origin/master)

How to merge your current branch with another branch?

Step 1: Commit and push your changes to your current branch.
Step 2: Switch from your current branch to the branch you want to merge.
Step 3: git pull. Make sure the branch you want to merge  has the latest version before you merge your branches, otherwise you may face conflicts or other problems.
Step 4:git merge <branch-name> you can merge your feature branch into the branch you want to merge.
Step 5: push your changes.

How to resolve conflicts?

Step1: To resolve a conflict git checkout master and pull the latest.
Step2: git checkout <target branch>.
Step3: git merge master

After this process if everything is fine no error message will appear. If it's not, a message will appear that says "This branch has conflicts that must be resolved". In this stage you'll need to fix the conflict manually in Github or your code editor. Open your code editor and accept the current changes (what's on your branch), incoming changes (master) accept one of these options or both according to your needs.

Top comments (1)

eric23 profile image

Thanks for the tips!
I need to get better with using branches.