All git commands you need — get rid of merge conflicts



 Git is a very popular tool for managing codes across small and large teams. GitHub, GitLab, and BitBucket are popular sites where teams generally host their git repositories. With git, you can efficiently work in teams compared to conventional code uploading methods such as FTP.

You can create multiple branches for managing codes e.g. production branch, development branch, staging branch, or feature changes branch. With proper knowledge and commands, you don’t need to worry about taking backups of your codes.

You can revert to a previous commit state or merge your code with other developers’ codes in your own branch and re-merge your branch into an original branch with the following commands.


  Clone repository:

  git clone <repo_url>


  Clone branch:

  git clone -b <branch> <repo_url>


  Create a new branch:

  git checkout -b <branch>


  Switch to an existing branch:

  git checkout <branch>


  Delete branch locally:

  git branch -d <branch>


  Delete branch locally forcefully discarding staged changes:

  git branch -D <branch>


  Commit changes:

  git add <files> / git add .

  git commit -m “Changes description”


  Push changes and set upstream branch A:

  git push -u origin A


  Push changes to the current upstream branch:

  git push


  Push changes from the current branch to another branch B:

  git push origin B


  Reset all local commits:

  git reset — hard origin/<branch_name>


  Reset last local commits:

  git reset — soft origin/<branch_name>


  Pull changes from the current upstream branch:

  git pull


  Pull changes from branch A:

  git pull origin A


  Merge branch B into A:

  git checkout A

  git merge B


  Get current branch:

  git branch — show-current


  View last commits:

  git log — name-status HEAD^..HEAD


  Reset to a commit:

  git reset — hard 1caa56819d4db3e88a827d32e57268f29b42a5d6


Comments

Ask a Question

Name

Email *

Message *

Popular posts from this blog

Get current week number from Date C#

Get the number of weeks in a month C#